Home  >  Article  >  php教程  >  使用Zend Framework框架中的Zend_Mail模块发送邮件

使用Zend Framework框架中的Zend_Mail模块发送邮件

WBOY
WBOYOriginal
2016-06-13 10:40:53875browse

      大家都知道Zend Framework是由zend公司所开发的一款标准的PHP5版本的框架,他所包括了几乎我们常所使用到的功能模块,如 feed,mail,cache,db等等,今天我们主要是介绍Zend_Mail模块,来帮助我们及时的把应用的信息发向管理员,发向客户。 

      下面是我所写的一代码块,这代码是通过SMTP方式来发送邮件,需要提供提供用户名,密码和主机地址,这也是我们常所使用的邮件登录方式。

require_once Zend/Mail.php;
require_once Zend/Mail/Transport/Smtp.php;
class logMail {

private static $_config=array(auth=>login,
username=>XXXX@yuyu.com,
password=>XXXX);
private static $_mail = null;
private static $_transport = null;


public function __construct($title, $body){
try {
$shijie=date(Y-m-d);
$transport = new Zend_Mail_Transport_Smtp(mail.yuyu.com,self::$_config);
$mail = new Zend_Mail();
$mail->setBodyText($body);
$mail->setFrom(XXX@yuyu.com, XXX);
$mail->addTo(XXX@163.com, XXX);
$mail->setSubject($title.(.$shijie.));
$mail->send($transport);
return true;
}catch(Exception $e) {
$e->getTrace();
return false;
}
return false;
}

public static function logMail($title, $body) {
$this->__construct($title, $body);
}

public function __destruct() {

}
}
new logMail(Test,Test); 

      通过上面的代码,大家只需要把用户名和密码修改为自己的,便可以在应用中随意的应用他来,更为重要的应用可能更多是日志的发送和项目的发送!
 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn