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:
- function sendmail($tomail,$title,$content)
- {
- / * Set the mail information * /
- $email_set = C('EMAIL_SET');
- Vendor('phpmailer.class#phpmailer');
- Vendor ( "phpmailer.class the SMTP #"); // optional, otherwise they will be included in the class.phpmailer.php
- mail = $ new new PHPMailer (to true); // instantiate class PHPMailer, true represents an exception is thrown if an error occurs
- mail- $> IsSMTP (); // using SMTP
- mail- $> the CharSet = "UTF-. 8"; // set message encoding
- $mail->Host = $email_set['Host']; // SMTP server
- mail- $> SMTPDebug = 1; // enable SMTP debugging 1 = errors 2 = messages
- mail- $> = SMTPAUTH to true; // server requires authentication
- mail- $> Port = $ email_set [ 'Port']; // set the port
- // $mail->SMTPSecure = "ssl";
- /*
- $mail->SMTPSecure = "ssl";
- $mail->Host = "smtp.gmail.com";
- $ Mail-> Port = 465;
- */
- mail- $> the Username = $ email_set [ 'email_user']; // the SMTP server user account
- mail- $> Password = $ email_set [ 'email_pwd']; // the SMTP server user password
- 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
- if (is_array($tomail)){
- foreach ($tomail as $m){
- $mail->AddAddress($m, 'user');
- }
- }else{
- $mail->AddAddress($tomail, 'user');
- }
- $mail->SetFrom($email_set['email'],$email_set['email_name']);
- // $ mail-> AddAttachment ( './ img / phpmailer.gif'); // add attachments, if there are a plurality of attachment of the method is repeated
- $mail->Subject = $title;
- // The following is the message content relevant
- $mail->Body = $content;
- $mail->IsHTML(true);
- // $ body = file_get_contents ( 'tpl.html'); // get html page content
- // $mail->MsgHTML(eregi_replace("[]",'',$body));
- return $mail->Send()? true:false;
- }
2: the configuration parameters in the configuration file, as follows:
- /*E-Mail settings*/
- 'EMAIL_SET'=>array(
- 'Host'=> "smtp.163.com",
- 'Port'=>'25',
- 'email_user'=>'liuying',
- 'email_pwd'=>'123456',
- 'email'=>'[email protected]',
- 'email_name' => '86 market network '
- )
3. Test transmission code, the code is as follows:
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 .