Development

RFC/1.2/email: myMailer.class.php

You must first sign up to be able to contribute.

RFC/1.2/email: myMailer.class.php

File myMailer.class.php, 1.2 kB (added by FabianLange, 9 years ago)

very simple wrapper that solved 95% of my use cases

Line 
1 <?php
2 class myMailer {
3
4     static function sendTemplateEmail($from, $to, $subject, $module, $action){
5         return self::sendEmail($from, $to, $subject, sfContext::getInstance()->getController()->getPresentationFor($module, $action));
6     }
7
8     static function sendEmail($from, $to, $subject, $body){
9         require_once dirname(__FILE__) . "/Swift/Swift.php";
10         require_once dirname(__FILE__) . "/Swift/Swift/Connection/SMTP.php";
11         
12         $swift = new Swift(new Swift_Connection_SMTP("localhost", 25));
13         $message = new Swift_Message($subject);
14         $message->setPriority(1);
15         $message->setCharset('utf-8');
16         if (strpos($from,'@our-corp')){
17             $body = "<img src=\"" .$message->attach(new Swift_Message_Image(new Swift_File(sfConfig::get('sf_web_dir').'/images/logo.gif'))). "\" /><br />".$body;
18             $from = new Swift_Address($from, "Our Corp Mailer");
19         }
20         
21         $message->attach(new Swift_Message_Part($body, "text/html"));
22         if (!$swift->send($message, $to, $from)) {
23             sfContext::getInstance()->getLogger()->debug("Message failed to send");
24         } else {
25             sfContext::getInstance()->getLogger()->debug("Message sent");
26         }
27         $swift->disconnect();
28         return $message;
29     }
30 }