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 ...


Beginning Yii ...

I'm very excited about a new Yii Training course that has just been published.

The course is designed for anyone wanting to learn Yii, whether new to frameworks or converting from another.

Eight chapters, each having five videos of between 3 and 5 minutes, take you through the basics of the Yii Framework, building a web application step-by-step.

Save 40% - introductory offer $20.99 / £13.19 / €16.19 / A$20.99

Leave a Comment

twitterfacebookgooglelinkedin https://me.yahoo.com