ThinkPHP mail sending class

Source: Internet
Author: User

Recently, I am working on a project that requires the email sending function. If the server sends an email, the server must have a link to the email server to perform the following steps. Now I want to share with you the following steps, A dedicated email sending class

/*** System email sending function * @ param string $ to recipient's email * @ param string $ name recipient's name * @ param string $ subject * @ param string $ body email content * @ param string $ attachment List * @ return boolean */function think_send_mail ($, $ name, $ subject = '', $ body ='', $ attachment = null) {$ config = C ('Think _ EMAIL '); vendor ('phpmailer. class # phpmailer '); // export the class from the PHPMailer directory. phpmailer. php files $ mail = new PHPMailer (); // PH PMailer object $ mail-> CharSet = 'utf-8'; // set the mail encoding, the default ISO-8859-1, this must be set if you send Chinese, otherwise garbled $ mail-> IsSMTP (); // set the SMTP service $ mail-> SMTPDebug = 0; // disable the SMTP debugging function // 1 = errors and messages // 2 = messages only $ mail-> SMTPAuth = true; // enable the SMTP authentication function $ mail-> SMTPSecure = 'ssl '; // use the security protocol $ mail-> Host = $ config ['smtp _ host']; // SMTP server $ mail-> Port = $ config ['smtp _ port']; // SMTP server PORT number $ mail-> Username = $ config ['smtp _ US ER ']; // SMTP Server Username $ mail-> Password = $ config ['smtp _ pass']; // SMTP server password $ mail-> SetFrom ($ config ['from _ EMAIL '], $ config ['from _ name']); $ replyEmail = $ config ['reply _ e-mail ']? $ Config ['reply _ EMAIL ']: $ config ['from _ EMAIL']; $ replyName = $ config ['reply _ name']? $ Config ['reply _ name']: $ config ['from _ name']; $ mail-> AddReplyTo ($ replyEmail, $ replyName ); $ mail-> Subject = $ subject; $ mail-> MsgHTML ($ body); $ mail-> AddAddress ($ to, $ name); if (is_array ($ attachment )) {// Add an attachment foreach ($ attachment as $ file) {is_file ($ file) & $ mail-> AddAttachment ($ file );}} return $ mail-> Send ()? True: $ mail-> ErrorInfo ;}

This function can only be used in ThinkPHP and must be supported by the phpmailer extension;
Phpmailer extension Directory: ThinkPHP/Extend/Vendor/PHPMailer/class. phpmailer. php
Phpmail:

Https://code.google.com/a/apache-extras.org/p/phpmailer

To use this function, you must add the following configuration items to the project:

// Configure 'think _ emess' => array ('smtp _ host' => 'smtp .aaa.com ', // SMTP server 'smtp _ port' => '123 ', // SMTP server port 'smtp _ user' => 'mail @ aaa.com ', // SMTP Server Username 'smtp _ pass' => 'Password ', // SMTP server password 'from _ EMAIL '=> 'mail @ aaa.com', // sender EMAIL 'from _ name' => 'thinkphp ', // The sender NAME 'reply _ EMAIL '=> '', // if the reply email is left blank, It is the sender EMAIL.) 'reply _ name' => '', // if the reply name is left blank, It is the sender name )),



Friends who like to discuss can join a group of 252799167

This article is from the "Thunder" blog, please be sure to keep this source http://a3147972.blog.51cto.com/2366547/1221287

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.