Another code for sending emails through TP

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn how to use the email sending system found by tp. It will not succeed after trial on this server, specially changed to this type of email sending
In config. php, Please modify the account password and smtp as needed 'Think _ EMAIL '=> array (
'Smtp _ host' => 'smtp .qq.com ', // SMTP Server
'Smtp _ port' => '25', // SMTP server PORT
'Smtp _ user' => '6 @ qq.com ', // SMTP Server Username
'Smtp _ pass' => '123', // SMTP server password
'From _ EMAIL '=> '6 @ qq.com', // sender EMAIL
'From _ name' => 'cc', // sender NAME
'Reply _ EMAIL '=> '', // REPLY to the EMAIL (if left blank, It is the sender EMAIL)
'Reply _ name' => '', // reply name (if left blank, It is the sender NAME)
),
Add a method to index or other controllers and copy the following code. Import ("@. LibHM. Smtp"); // mail sending class
$ Config_mail = C ('Think _ EMAIL ');
$ Smtpserver = $ config_mail ['smtp _ host']; // SMTP Server
$ Smtpserverport = $ config_mail ['smtp _ port']; // SMTP server PORT
$ Smtpusermail = $ config_mail ['from _ EMAIL ']; // user EMAIL address of the SMTP server
$ Smtpuser = $ config_mail ['smtp _ user']; // USER Account of the SMTP server
$ Smtppass = $ config_mail ['smtp _ pass']; // user password of the SMTP server

$ Smtpemailto = $ uemail; // who to send
$ Mailsubject = $ subject; // Email subject
$ Mailtime = date ("Y-m-d H: I: s ");
$ Mailbody = $ body; // email content

$ Utfmailbody = iconv ("UTF-8", "GB2312", $ mailbody); // convert the email code
$ Mailtype = "HTML"; // The email format (HTML/TXT). TXT is a text email.

$ Smtp = new smtp ($ smtpserver, $ smtpserverport, true, $ smtpuser, $ smtppass); // here, true indicates that authentication is used; otherwise, authentication is not used.
$ Smtp-> debug = FALSE; // whether to display the sent debugging information FALSE or TRUE
$ Ret = $ smtp-> sendmail ($ smtpemailto, $ smtpusermail, $ mailsubject, $ utfmailbody, $ mailtype );
Returns true if the email is successfully sent.

Smtp.class.rar (2.18 KB download: 373 times)

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.