Everyone knows that Zend Framework is a standard PHP5 version of the framework developed by zend Company. It includes almost the functional modules we often use, such as feed, mail, cache, db, etc. Today we It mainly introduces the Zend_Mail module to help us send application information to administrators and customers in a timely manner.
The following is a code block I wrote. This code is used to send emails through SMTP. You need to provide a username, password and host address. This is also the email login method we often use.
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);
Through the above code, everyone only needs to change the username and password to their own, and then they can use it in the application at will. The more important application may be the sending of logs and projects!