Use Zend_Mail in ZendFramework to send emails in PHP Framework
Source: Internet
Author: User
As we all know, ZendFramework is a standard PHP5 framework developed by zend. It includes almost all of the function modules we often use, such as feed, mail, cache, db, etc. today we mainly introduce the Zend_Mail module to help us send application information to administrators and customers in a timely manner. SyntaxH everyone knows that Zend Framework is a standard PHP5 Framework developed by zend. It includes almost all of the function modules we often use, such as feed, mail, cache, db, etc. today we mainly introduce the Zend_Mail module to help us send application information to the administrator and the customer 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 the user name, password, and host address. this is also the usual email logon method.
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, you only need to change the user name and password to your own, and then you can freely apply the user name and password in the application, more important applications may be log sending and project sending!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service