include_once 'swift_required.php';
class TheMailer {
private $mailer;
private $message;
function __construct($serverAddress, $portNumber, $mailSecurity, $servUserName, $servPassword, $senderDetails, $transportType) {
$trans = Swift_SmtpTransport::newInstance($serverAddress,$portNumber, $mailSecurity)
->setUsername($servUserName)
->setPassword($servPassword);
$this->mailer = Swift_Mailer::newInstance($trans);
//$sendDetails is an array
$this->message = Swift_Message::newInstance()
->setFrom($senderDetails);
}
public function sendMessage($username, $userEmailAddress, $themessage, $templatePath, $messageSubject) {
try {
$this->message->setTo($userEmailAddress)->setBody($themessage);
//not using the $templatePath for now.template path is hardcoded
//now how to add the image to the message object.I guess i cannot use the Swift_FIle anymore nor use any swift class inside the template
//file to create something like cid or Embedded object.so how?
$this->message->addPart(file_get_contents("template.html"),'text/html');
$this->message->setSubject($messageSubject);
echo $this->mailer->send($this->message);
} catch (Exception $ex)
{
echo "Error sending the message".$ex->getMessage();
}
}
}
}