Thinkphp 3.2 Demo Case series "Phpmailer bulk Email"

Source: Internet
Author: User

But e-mails and text messages still have important meanings and advantages in some scenes.

1:0 cost, no charge for sending mail;

2: Rich content and large amount of mail can be lengthy;

3: Increase the number of visits, users can easily access the site through the link in the mail;

Well, come down here. Integrated messaging system for thinkphp;

Example Project: Https://github.com/Tinywan/ThinkPhpStudy

First, the introduction of Phpmail

Copy two files from the sample project to your own project;

/thinkphp/library/org/nx/class. Phpmailer. php; /thinkphp/library/org/nx/class. smtp.php;

Second, set the configuration item

// *********************************** mail server **********************************    ' Email_from_name '        //  sender    ' email_smtp '//               SMTP    ' Email_ USERNAME '         //  account    ' Email_password '//           authorization password instead of login password

Three, configuration 163 box:

The first thing to do is to turn on the SMTP service:

The information in the configuration file is here:

Note: In the process is to set an authorization password, where the authorization password is the configuration file required in the password, otherwise, otherwise, SMTP Connect () failed

' Email_password '         = ' your password//authorization password instead of login password

Iv. the actual code for sending the message, which is written in the function () functions (in the thinkphp framework)

/** * Send mail * @param string $address The email address that needs to be sent to multiple addresses needs to be written in array form * @param string $subject title * @param string $content content * @return Boolean is successful*/functionSend_email ($address,$subject,$content){    $email _smtp=c (' Email_smtp '); $email _username=c (' Email_username '); $email _password=c (' Email_password '); $email _from_name=c (' Email_from_name '); if(Empty($email _smtp) ||Empty($email _username) ||Empty($email _password) ||Empty($email _from_name)){        return Array("Error" =>1, "message" = "Mailbox Configuration not complete"); }    require'./thinkphp/library/org/nx/class.phpmailer.php '; require'./thinkphp/library/org/nx/class.smtp.php '; $phpmailer=New\phpmailer (); //set Phpmailer to send email using an SMTP server    $phpmailer-issmtp (); //set to HTML format    $phpmailer->ishtml (true); //set the character encoding of the message '    $phpmailer->charset= ' UTF-8 '; //set up the SMTP server.     $phpmailer->host=$email _smtp; //set to "Require verification"    $phpmailer->smtpauth=true; //Set user name    $phpmailer->username=$email _username; //Set Password    $phpmailer->password=$email _password; //sets the From field of the message header.     $phpmailer->from=$email _username; //Set Sender name    $phpmailer->fromname=$email _from_name; //add a recipient address that can be used multiple times to add multiple recipients    if(Is_array($address)){        foreach($address  as $ADDRESSV){            $phpmailer->addaddress ($ADDRESSV); }    }Else{        $phpmailer->addaddress ($address); }    //set the message header    $phpmailer->subject=$subject; //set the message body    $phpmailer->body=$content; //send the message.     if(!$phpmailer-Send ()) {        $phpmailererror=$phpmailer-errorinfo; return Array("Error" =>1, "message" = =$phpmailererror); }Else{        return Array("Error" =>0); }}

Example of sending a mail call function:

 /** * Send mail*/     Public functionSend_email () {$name= I (' post.name ', ' This is a test mail name ')); $address= I (' post.address ', ' This is a test mail sent to the address '); $phone= I (' Post.phone ', ' 13669361192 '); $email= ' [email protected] '; $str= <<<HTML Name:$name<br>Address:$address<br>Phone Number:$phonehtml; $result= Send_email ($email, ' This mail is what I used to do the test, pro! ‘,$str); if($result[' error '] = = 1) {            Var_dump($result);  die; }        Var_dump(' Send complete '); }

Base Source: http://baijunyao.com

Thinkphp 3.2 Demo Case series "Phpmailer bulk Email"

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.