Next4Me
 All Classes Files Functions Variables
SendMail.php
1 <?php
3  function send($html,$toEmail, $toName,$subject){
4  $resultId = 0;
5  $page="SendMail.php";
6  $method="send";
7  $result=json_encode($html." | ".$toEmail." | ".$toName." | ".$subject);
8  $message="";
9  $type="1";
10  $this->ErrorCode = new Application_Model_ErrorCode;
11  $this->Log = new Application_Model_Log;
12 
13  $cfg=Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOptions();
14  $username=$cfg['global']['username'];
15  $password=$cfg['global']['password'];
16  $port=$cfg['global']['port'];
17  $mailServer=$cfg['global']['mailServer'];
18  $fromEmail=$cfg['global']['fromEmail'];
19  $fromName=$cfg['global']['fromName'];
20  $smtpOption=array(
21  'auth' => 'login',
22  'username' => $username,
23  'password' => $password,
24  'port' => $port
25  );
26 
27  $mailTransport= new Zend_Mail_Transport_Smtp($mailServer, $smtpOption);
28  $mail = new Zend_Mail();
29  $mail->setBodyHtml($html);
30  $mail->setFrom($fromEmail, $fromName);
31  $mail->addTo($toEmail, $toName);
32  $mail->setSubject($subject);
33 
34  //Send it!
35  $sent = true;
36  try {
37  $mail->send($mailTransport);
38  $resultCode= "Mail was sent successfully.";
39  } catch (Exception $e){
40  $resultCode=$e->getMessage();
41  $resultId=101;
42  $type=3;
43  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
44  }
45 
46  //Do stuff (display error message, log it, redirect user, etc)
47 
48  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
49  return $response;
50  }
51 }