Zend Framework 使用SMTP服务器发送邮件

Posted by windea on October 19, 2011

set_include_path(dirname(__FILE__) . ‘/library’);
require(‘Zend/Mail.php’);
require(‘Zend/Mail/Transport/Smtp.php’);

$config = array(‘auth’ => ‘login’,
‘username’ => ‘windea’,
‘password’ => ‘**’,
);

$transport = new Zend_Mail_Transport_Smtp(‘smtp.163.com’, $config);
$mail = new Zend_Mail(‘UTF-8′);
$mail->setFrom(‘xxxx@163.com’, ‘发件人’);
$mail->addTo(‘xxxx@163.com’[/email], ‘收件人’);
$mail->setSubject(‘Test’);
$mail->setBodyHtml(‘HTML Mail’);
$mail->send($transport);

ps:如果使用Gmail的SMTP服务器需要再加几个参数,红色部分是关键哦

$config = array(‘auth’ => ‘login’,
‘username’ => ‘windea’,
‘password’ => ‘**’,
                       ‘ssl’ => ‘tls’,
                       ‘port’ => 587,
);