nettrinity
(Thanhvn Info)
September 30, 2011, 3:10pm
1
Dear you,
I am trying to send my first email using yii framework extension yiiMail (http://www.yiiframew …extension/mail/)
It seems the document is not very detailed (many steps are skipped, which is killing newbies like me!). I configured the following in main.php
'import'=>array(
'application.models.*',
'application.components.*',
'ext.mail.YiiMailMessage',
),
'mail'=> array(
'class' => 'ext.mail.YiiMail',
'transportType' => 'php',
'viewPath' => 'application.views.mail',
'logging' => true,
'dryRun' => false
),
Here is the code in controller to send email:
public function ActiontestEmail ()
{
$message = new YiiMailMessage;
$message->setBody('Message content ', 'text/html');
$message->subject = 'subject ';
$message->addTo('xu.shenxin@gmail.com');
$message->from = Yii::app()->params['admin33Email'];
Yii::app()->mail->send($message);
}
I am using this url to run this action: http://localhost/vs/ …=user/testemail
The result is a white screen. nothing is sent. Where do I input password, or smtp server? what I should do step by step to make it work?
Thank you!
joblo
(Joe)
September 30, 2011, 3:34pm
2
'mail' => array(
'class' => 'ext.yii-mail.YiiMail',
'transportType' => 'smtp',
'transportOptions'=>array(
'host'=>'smtp.host.xy',
//'encryption'=>'tls',
'username'=>'user',
'password'=>'password',
'port'=>25,
),
'viewPath' => 'application.views.mail',
'logging' => true,
'dryRun' => false
),
nettrinity
(Thanhvn Info)
September 30, 2011, 4:06pm
3
thanks!
Let me try that. Can you tell me what is the different between php and smtp for transportOptions? or point me to a source to find out.
joblo
(Joe)
September 30, 2011, 4:18pm
4
transportType = ‘php’ uses the PHP mail() function and doesn’t connect to a smtp-server.
fleuryc
(Clement Fleury)
December 22, 2011, 12:52pm
6
Hi!
I want to use a Gmail account as SMTP server.
When I use the same config as proposed by Joblo, I get this error :
fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:func(143):reason(267)
in : /protected/extensions/yii-mail/vendors/swiftMailer/classes/Swift/Transport/StreamBuffer.php(233)
I read this thread that says that in order to use Gmail with Swiftmailer, we should use options like :
authentication: :plain
enable_starttls_auto: true
in order to enable tls encryption only AFTER the authentication is done…
Is there a way (and how) to do that with yii-mail?
Thx
Technocrat
(Spamaddress)
December 22, 2011, 11:45pm
7
I think the issue you are having is with your server and not Yii-Mail. If you google your error a bit more you will find that it looks like your OpenSSL is outdated or has an error.
vasireddy
(Kiranvasi)
January 7, 2012, 9:56am
8
fleuryc:
Hi!
I want to use a Gmail account as SMTP server.
When I use the same config as proposed by Joblo, I get this error :
fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:func(143):reason(267)
in : /protected/extensions/yii-mail/vendors/swiftMailer/classes/Swift/Transport/StreamBuffer.php(233)
I read this thread that says that in order to use Gmail with Swiftmailer, we should use options like :
authentication: :plain
enable_starttls_auto: true
in order to enable tls encryption only AFTER the authentication is done…
Is there a way (and how) to do that with yii-mail?
Thx
Uncomment php_openssl.dll in your php.ini file ( I mean load php_openssl.dll)
Regards
Yii Fan
FedyaNyet
(Teddywolf23)
April 6, 2012, 2:12am
9
if you use the SwiftMailer extension with a gmail account, i got it working by doing the following:
In the swift mailer class modify smtpTransport so it allows for ssl authentication as follows:
public function smtpTransport($host=null, $port=null,$ssl=null) {
return Swift_SmtpTransport::newInstance($host, $port,$ssl);
}
then in config/main.php, add following component:
'components'=>array(
//...
'swiftMailer' => array(
'class' => 'ext.swiftMailer.SwiftMailer',
),
//...
)
and to actually send the message do the following:
$SM = Yii::app()->swiftMailer;
// New transport
$transport = $SM
->smtpTransport('smtp.gmail.com', 465,"ssl")
->setUsername('username@gmail.com')
->setPassword('password');
// Mailer
$mailer = $SM->mailer($transport);
// New message
$message = $SM ->newMessage('foo')
->setFrom($array('username@gmail.com' => 'Your Name'))
->setTo(array('receiver@somewhere.com'=>'Mr.Stranger's Name'))
->setBody('k thnx bye!');
$results = $mailer->send($message);
THAT’S IT!
nickcv
(N Puddu)
July 11, 2012, 1:10pm
10
i don’t know if something actually changed since Fedya posted his solution, but now you can just set those options into your configuration file [/protected/config/main.php]:
'mail' => array(
'class' => 'ext.yii-mail.YiiMail',
'transportType' => 'smtp',
'transportOptions'=>array(
'host'=>'smtp.gmail.com',
'encryption'=>'ssl',
'username'=>'user@gmail.com',
'password'=>'password',
'port'=>465,
),
'viewPath' => 'application.views.mail',
'logging' => true,
'dryRun' => false
),
There is an error
array should not be $array in the code block…cost me 30 minutes of sorting out what the heck was wrong.
Thanks it was very helpful in general!