The example of this article describes the Zend_Mail of the Zend Framework framework to implement the verification function of sending email and solve the method of garbled title. I share it with you for your reference. The details are as follows:
The Zend_Mail component in Zend Framework is very convenient to use. It provides a universal way to write and send emails with text content. Of course, it is also compatible with the MIME standard. The function of multiple multi-segment email messages. Zend_Mail uses the default Zend_Mail_Transport_SendMail transport or can send our emails through Zend_Mail_Transport_Smtp.
Zend_Mail is the simplest email function. Send it through Zend_Mail_Transport_Sendmail. We only need to specify a recipient, a subject, an email content and a sender of the email. The code is as follows (with comments:):
<?php require_once 'Zend/Mail.php'; $mail = new Zend_Mail("UTF-8");//设置邮件编码 $mail->setBodyText('你的邮件内容放在这里!.') //发送电子邮件地址以及一些发送人的说明信息 ->setFrom('fromemail@example.com', '发送人的说明信息') //收信人电子邮件地址以及一些收信人的说明信息 ->addTo('toemail@example.com', '收信人的说明信息') //电子邮件标题,解决乱码 ->setSubject("=?UTF-8?B?".base64_encode('电子邮件标题')."?=") ->send(); ?>
The other one is to send an email through an SMTP Email. But you need to configure your email server. You can go to GOOGLE for this step. I won’t say more here. I can use GOOGLE to send emails here. After my test, my email There is no problem when emails are sent to my Gmail and 163 (NetEase) mailboxes. The garbled code problem has also been solved. The title length limit problem has not appeared either. In the past, I changed the functions in Zend_Mail by referring to the Internet. Now I use 1.6 The version of Zend Framework doesn't seem to have such a problem... I think the ZF team has fixed the bug in it... Haha...
The following is the code of my own implementation:
<?php require_once ROOT_PATH . '/Zend/Mail.php'; require_once ROOT_PATH . '/Zend/Mail/Transport/Smtp.php'; $mail = new Zend_Mail("UTF-8");//设置邮件编码 $config = array( 'auth'=>'login', 'username'=>"kylingood",//电子件用户名 'password'=>"这里是填写你电子邮件密码", 'ssl'=>"ssl" ); $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com',$config); $mail->setDefaultTransport($transport); $mailcontent='欢迎您的到来!<br /> 您的注册名为: '.$thisArray ['username'].'<br /> 您的密码为:'.$thisArray ['userpass'].' <br /> 请您点击这里的地址:<a href="#"><font color="red">激活 </font> </a>您的帐号! 请尽快删除此邮件,以免别人偷看到您的密码<br /> 如果忘了密码, 可以到社区写信请管理员重新设定<br />'; $mail->setBodyHtml($mailcontent);//可以发送HTML的邮件.真方便! $mail->setFrom('kylingood@gmail.com', 'kylingood'); $mail->addTo($email, 'kylingood'); $title=$thisArray ['username'].',用户您好,这是网站激活验证邮件!'; $mail->setSubject("=?UTF-8?B?".base64_encode($title)."?="); $mail->send(); ?>
Okay Okay.. This is basically the principle of using Zend_Mail to send emails. Of course, there are more advanced uses. For example, sending attachments via email, sending multiple emails at one time, and using different Transport objects to send them. Different emails... You can refer to the ZF manual to do it... I hope you can communicate more...
I hope this article will be helpful to everyone's PHP programming based on the Zend Framework framework.
For more Zend_Mail implementation of verification function for sending emails and methods to solve garbled headers, please pay attention to the PHP Chinese website for email-related articles!