Yii – simple email and mail merge

I needed an email mechanism for a customer that was light and easy to configure.

Yii extensions

I tried several email extensions from the Yii website all of which I found overly complex to setup and use.  I then remembered that I had used a simple class on a PHP website a few years previously and went back to look at how easy it would be to lift out and use in my Yii application.

It turned out to be a very compact set of 3 classes, which were well documented in the code and easy to setup.

All you need to do is copy these three classes into your models directory and then you can use them within your code as any other Yii class:

     $mail = new PHPMailer(); // defaults to using php "mail()"
     $mail->IsSendmail();
     $mail->WordWrap=70;
     $mail->AddReplyTo("[email protected]","");
     $mail->SetFrom("[email protected]", 'Another Gmail address');
     $mail->Subject    = $subject;
     $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
     if($mail->Send()) {
        echo "Message sent to $to!
";
        return true;
    }


Further resources:-
Software: PHPMailer - PHP email class
| Contact: via sourceforge.net support pages (also www.worxware.com) |
| Info: http://phpmailer.sourceforge.net |
| Support: http://sourceforge.net/projects/phpmailer/ |
| ------------------------------------------------------------------------- |
| Admin: Andy Prevost (project admininistrator) |
| Authors: Andy Prevost (codeworxtech)
| : Marcus Bointon (coolbru)
| Founder: Brent R. Matzelle (original founder)

Let’s Start a Project!

Contact Me