<?php
require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';
class logMail {
private static $_config=array('auth'=>'login',
'username'=>'xx@xx.xx',//发送使用的邮箱
'password'=>'xx'); //发送使用的邮箱的登录密码
private static $_mail = null;
private static $_transport = null;
public function __construct($title, $body,$address)//参数为邮件的主题,内容和地址
{
try {
$transport = new Zend_Mail_Transport_Smtp('smtp.xx.xx',self::$_config); //发送的SMTP服务器地址
$mail = new Zend_Mail('GBK'); //实例化发送邮件对象
$mail->setBodyHtml($body); //发送邮件的主体
$mail->setFrom('xx@xx.xx', ''); //定义邮件发送使用的邮箱
$mail->addTo("$address", 'xx@xx.xx'); //定义邮件的接收邮箱
$mail->setSubject($title); //定义邮件主题
$mail->send($transport); //执行发送操作
return true;
}
catch(Exception $e) {
$e->getTrace();
return false;
}
return false;
}
public static function logMail($title, $body,$address) {
$this->__construct($title, $body,$address);
}
}
if (new logMail('Test Mail','Test Content',"xx@xx.xx"))
{
echo "发送成功";
}
else
{
echo "发送失败";
}
PHP使用Zend Mail发送邮件
最新推荐文章于 2021-03-19 13:50:48 发布