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("someone@gmail.com","");
     $mail->SetFrom("another@gmail.com", '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)


Did you know you can hire me?

I take on projects of all sizes. From Consulting to large Development Projects.

If you're starting a new Yii project and would like some help to get setup and running or you need some help with a particular module or you just need someone to develop the whole dang thing, then just ask ...


Jumpstart Yii2 ... Coming Soon!

I'm in the process of planning a new course on Yii2 and want your feedback.

What is your preferred format? What did you think of my Yii 1.x video course "Beginning Yii"?

What would you like to see different?

How much would you pay?

Leave a Comment

twitterfacebookgooglelinkedin https://me.yahoo.com