The Zend_mail of Zend framework framework to realize the verification function of sending email message and the method of solving the title garbled _php example

Source: Internet
Author: User
Tags zend zend framework

In this paper, the Zend_mail of Zend Framework framework is introduced to realize the verification function of email message and the method of solving the title garbled. Share to everyone for your reference, specific as follows:

Zend_mail This component in the Zend Framework is very convenient to use. It provides a general-purpose message for writing and sending text content, and of course it is also compatible with the MIME standard multiple segments of mail messages. Zend_mail through the default Zend_mail_transport_sendmail transmission or can be zend_mail_ TRANSPORT_SMTP to send us the email.

Zend_mail sends the simplest message function. Send it through zend_mail_transport_sendmail. We just specify a recipient of the message, a topic, a message content, and a sender. Its code is as follows (annotated:):

<?php
require_once ' zend/mail.php ';
$mail = new Zend_mail ("UTF-8");/set the message encoding
$mail->setbodytext (' Your email content is here!. ')//Send email address and some sender's description information
-> Setfrom (' fromemail@example.com ', ' sender's description ')//email address of the addressee as well as some information on the addressee's instructions
->addto (' toemail@example.com ', ' Addressee's description information ')//email title, Resolve garbled
->setsubject ("=? UTF-8? B? ". Base64_encode (' e-mail headers '). "? = ")  ->send ();
? >

The other is sending e-mail through an SMTP message. But you need to configure your mail server. This step you can go to Google. I'm not here to say more. I am here to keep up with Google to implement email. After my test. My email to my gmail and 163 (NetEase) mailbox is no problem. Garbled problem also solved. The question of the title length limit does not appear. Used to be a reference to their own online changes in the Zend_mail inside the function. Now, with the 1.6 version of the Zend Framework, there seems to be no such problem. I think the ZF team changed the bugs inside ... Oh..

Here is the code for your 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");/Set message encoding $config = Array (' auth ' => ' login ', ' username ' => ' kylingood ',//electronic user name ' PASSW ')
Ord ' => ' here is to fill in your email password, ' SSL ' => ' SSL ');
$transport = new Zend_mail_transport_smtp (' smtp.gmail.com ', $config);
$mail->setdefaulttransport ($transport); $mailcontent = ' Welcome to your arrival! <BR/> Your registration name is: '. $thisArray [' username ']. ' <br/> Your password is: '. $thisArray [' Userpass ']. ' <br/> Please click here Address: <a href= "#" ><font color= "Red" > Activation <
/FONT> </a> your account number!
Please delete this email as soon as possible so that someone else will steal your password <br/> If you forget your password, you can write to the community to ask the administrator to reset <br/> '; 
$mail->setbodyhtml ($mailcontent);//can send HTML messages. That's convenient!
$mail->setfrom (' kylingood@gmail.com ', ' Kylingood '); $mail->addto ($email, ' Kylingood ');
$title = $thisArray [' username ']. ', user Hello, this is the website activation verification mail! ' $mail->setsubject ("=? UTF-8? B? ". Base64_encode ($title). "?
="); $mail->send ();?> 

All right.. The principle is to send mail roughly with Zend_mail. Of course, there are more advanced points to use. For example, mail to send attachments. Send multiple e-mail messages at once. There is also the use of different transport objects to send different messages ... You can make reference to the ZF manual ... I hope you can communicate a lot.

More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on the Zend Framework.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.