thinkphp in how to send mail using phpmailer

phpmailer php send mail is the preferred developer of a plug-in to send a message, Here I introduce how to integrate phpmailer thinkphp framework, and there need to know friends can refer.

phpmailer Send e-mail function is very powerful, real experience today, briefly about the configuration, it was in thinkphp is used.

Configuration steps:

Background 1. Configure the message class, location admin / common / common.php code is as follows:

  1. function sendmail($tomail,$title,$content) 
  2. / * Set the mail information * / 
  3.         $email_set = C('EMAIL_SET'); 
  4.         Vendor('phpmailer.class#phpmailer'); 
  5.         Vendor ( "phpmailer.class the SMTP #");  // optional, otherwise they will be included in the class.phpmailer.php 
  6.          
  7.         mail = $  new new PHPMailer (to true);  // instantiate class PHPMailer, true represents an exception is thrown if an error occurs 
  8.          
  9.         mail- $> IsSMTP ();  // using SMTP 
  10.           mail- $> the CharSet = "UTF-. 8"; // set message encoding 
  11.           $mail->Host       = $email_set['Host']; // SMTP server 
  12.           mail- $> SMTPDebug = 1;                      // enable SMTP debugging 1 = errors 2 = messages 
  13.           mail- $> = SMTPAUTH to true;                   // server requires authentication 
  14.           mail- $> Port =  $ email_set [ 'Port'];                     // set the port 
  15.          // $mail->SMTPSecure = "ssl";      
  16.             /* 
  17.             $mail->SMTPSecure = "ssl";                  
  18.             $mail->Host       = "smtp.gmail.com";      
  19.             $ Mail-> Port = 465;                   
  20.             */ 
  21.          
  22.           mail- $> the Username =  $ email_set [ 'email_user'];  // the SMTP server user account 
  23.           mail- $> Password =  $ email_set [ 'email_pwd'];        // the SMTP server user password 
  24.           mail- $> AddReplyTo ( $ email_set [ 'In Email'], $ email_set [ 'email_name']);  Reply to this mailbox // recipient replies, the method may be performed a plurality of times 
  25.           if (is_array($tomail)){ 
  26.               foreach ($tomail as $m){ 
  27.                    $mail->AddAddress($m, 'user');  
  28.               } 
  29.           }else{ 
  30.               $mail->AddAddress($tomail, 'user'); 
  31.           } 
  32.           
  33.           $mail->SetFrom($email_set['email'],$email_set['email_name']); 
  34.         // $ mail-> AddAttachment ( './ img / phpmailer.gif'); // add attachments, if there are a plurality of attachment of the method is repeated 
  35.           $mail->Subject = $title; 
  36.          
  37.           // The following is the message content relevant 
  38.           $mail->Body = $content; 
  39.           $mail->IsHTML(true); 
  40.          
  41.           // $ body = file_get_contents ( 'tpl.html'); // get html page content 
  42.          // $mail->MsgHTML(eregi_replace("[]",'',$body)); 
  43.          
  44.          
  45.         return $mail->Send()? true:false; 

2: the configuration parameters in the configuration file, as follows:

  1. /*E-Mail settings*/ 
  2.     'EMAIL_SET'=>array( 
  3.        'Host'=> "smtp.163.com", 
  4.        'Port'=>'25', 
  5.        'email_user'=>'liuying', 
  6.        'email_pwd'=>'123456', 
  7.        'email'=>'[email protected]', 
  8.        'email_name' => '86 market network ' 
  9.   ) 

3. Test transmission code, the code is as follows:

sendmail ('[email protected] ',' hello ',' I am content ');

Links: https://pan.baidu.com/s/1v5gm7n0L7TGyejCmQrMh2g  extraction code: x2p5

free to share, but serious limitations of X, should click on the link or links fail Search plus population group number 936 682 608 .

Guess you like

Origin www.cnblogs.com/it-3327/p/11728949.html