Sending registration confirmations and password resets with Yii

I am currently using the yii-user extension which has registration confirmations built in. I am also using yii-mail with the SwiftMailer wrapper.

I have both of these components working independently but not sure what I have to do to have yii-user use this mail support to send out registration emails and password reset emails.

Can anybody provide some help with this?

Anybody using yii-user that has it functioning?

Yii-user uses regular php mail (which uses sendmail), so it just works.

Provided that you’re on a server where sendmail is set up properly.

What’s the issue? :)

Hi Jacmoe, like I said I can send emails so yes something must be working, but emails are not sending out through yii-user.

To test email functionality I used the code below (along with the SMTP config in the config file) and emails send just find.


$message = new YiiMailMessage;  

$message->setBody('Message content here with HTML', 'text/html');  

$message->subject = 'My Subject';  

$message->addTo('@gmail.com');  

$message->from = Yii::app()->params['adminEmail'];  

Yii::app()->mail->send($message);

Is there something that needs to be modified in yii-user or a controller added to send emails?

I don’t think you understand. :)

Yii-user uses regular php mail (IIRC), so test that:

http://www.php.net/m...nction.mail.php

If that doesn’t work, then change yii-user to use smtp. In your case YiiMailer.

I bet that’s the problem.

What kind of server are you using?

You are right I don’t understand.

I pulled this from yii-user


public static function sendMail($email,$subject,$message) {

    	$adminEmail = Yii::app()->params['adminEmail'];

	    $headers = "MIME-Version: 1.0\r\nFrom: $adminEmail\r\nReply-To: $adminEmail\r\nContent-Type: text/html; charset=utf-8";

	    $message = wordwrap($message, 70);

	    $message = str_replace("\n.", "\n..", $message);

	    return mail($email,'=?UTF-8?B?'.base64_encode($subject).'?=',$message,$headers);

	}

sendMail() and Mail() are not the same things right?

This is on my dev box built on a Mac using individual components with apache (no MAMP or XAMPP)

The PHP mail function is a wrapper around sendmail:

http://en.wikipedia.org/wiki/Sendmail

So if you haven’t set up your local sendmail properly, it will not work.

You either need to have a email server, or tell sendmail to use an external server.

Maybe you’re better off just rewriting the yii-user email functions to using YiiMailer instead? :)

Alternatively, get your hands dirty and learn how to configure your own email server.

And/or the intricacies of sendmail.

Thanks for the help. Although I don’t have it figured all out yet I did end up finding at least one problem with my sendmail config. Just learned that on a Mac sendmail seems to work in some manner with with postfix. By watching my mail log in terminal I can see that I am actually sending them from my system now, after that…well that seems to be another problem. I had to make a number of changes to get SwiftMailer to be recognized so I will see if some of those can crossover.

I finally got the mail issues sorted out on my Mac. There are many “how-to’s” out there but many lead you down a path of hours of troubleshooting. Just in case anyone has the same problem here is the one how to that actually worked. Let Postfix send mail through your Gmail Account – Snow Leopard

Thanks a lot! :)

I hope there’s some hints for *nix in there as I need to do this on my development box (Debian).