This article describes how to use Zend_Mail in the ZendFramework to verify Email sending and how to solve title Garbled text. It also analyzes in detail the specific steps of the Zend_Mail component to send emails, the solution to title Garbled text is provided. For more information, see the example in this article. The Zend_Mail In the Zend Framework provides the Email verification function and a solution to title Garbled text. We will share this with you for your reference. The details are as follows:
The Zend_Mail component in Zend Framework is very convenient to use .. it provides generic compilation and sending of text content emails. Of course, it is also compatible with the MIME standard multi-segment mail message function. in Zend_Mail, use the default Zend_Mail_Transport_SendMail for transmission or use Zend_Mail_Transport_Smtp to send our email.
Zend_Mail provides the simplest email sending function. sent via Zend_Mail_Transport_Sendmail. you only need to specify one email recipient, one subject, one email content, and one sender. its code is as follows (with annotations :):
<? Phprequire_once 'zend/Mail. php'; $ mail = new Zend_Mail ("UTF-8"); // set the email code $ mail-> setBodyText ('Put your email content here !. ') // The sender's email address and description of some senders-> setFrom ('fromemail @ example.com', 'sender's description information ') // recipient's email address and description of some recipients-> addTo ('email @ example.com ', 'recipient's description information') // email title, fix Garbled text-> setSubject ("=? UTF-8? B? ". Base64_encode ('email title ')."? = ")-> Send ();?>
The other is to send an email via SMTP. however, you need to configure your email server. in this step, You can GOOGLE it .. I will not talk about it here. I can keep GOOGLE here to send emails .. after my tests. I sent emails to my Gmail and Netease mailboxes. the garbled problem is also solved .. the title length restriction problem does not occur either .. I used to modify the Zend_Mail function on the Internet .. the Zend Framework of version 1.6 does not seem to have such a problem .. I think the ZF team has changed the BUG... haha ..
The following is your own implementation code:
<? Phprequire_once ROOT_PATH. '/Zend/Mail. php '; require_once ROOT_PATH. '/Zend/Mail/Transport/Smtp. php '; $ mail = new Zend_Mail ("UTF-8"); // set the email encoding $ config = array ('auth' => 'login ', 'username' => "kylingood", // electronic mail username 'Password' => "here is your email password", 'ssl '=> "ssl "); $ transport = new Zend_Mail_Transport_Smtp ('smtp .gmail.com ', $ config); $ mail-> setDefaultTransport ($ transport); $ mailcontent =' Welcome!
Your registration name is '. $ thisArray ['username'].'
Your password is '. $ thisArray ['userpass'].'
Click here to activate your account! Please delete this email as soon as possible to prevent others from stealing your password.
If you forget the password, you can write to the community and ask the Administrator to reset it.
'; $ Mail-> setBodyHtml ($ mailcontent); // you can send HTML emails. This is really convenient! $ Mail-> setFrom ('kylingood @ gmail.com ', 'kylingood'); $ mail-> addTo ($ email, 'kylingood '); $ title = $ thisArray ['username']. ', hello, this is the website activation verification email! '; $ Mail-> setSubject ("=? UTF-8? B? ". Base64_encode ($ title )."? = "); $ Mail-> send ();?>
Okay .. generally, Zend_Mail is used to send emails .. of course there are more advanced usage points. for example, sending an attachment via email .. send multiple emails at a time. there is also the use of different Transport objects to send different emails... you can refer to the ZF manual to do this... I hope you can talk more ..