About thinkphp3.2.3 integrated phpmailer

About thinkphp3.2.3 integrated phpmailer

 

1 I use phpmailer5.1 version of the first file decompression zoom to this location

 

Function inside the package 2

function email($email,$title,$content)
{
    // mail server 
    $ emailHost = 'smtp.163.com' ;
     // message send port 
    $ emailPort = '25 ' ;
    
    // mailing timeout 
    $ emailTimeout = '20 ' ;
     // sender's mailbox 
    $ emailUserName =' mailboxes just there to write ' ;
     // sender's mail password 
    $ emailPassword =' If you are here to write client license 163 code ' ;
     // Your name 
    $ emailFormName =' abc ' ;
     // recipient's mailbox 
    $ toemail = $ email ;
     // message headers 
    $ Subject = $ title ;
     // message content 
    $ the message = $ content ;

    Vendor ( 'phpmailer.class # PHPMailer'); // // Note that this is more important from PHPMailer class file directory guide class.phpmailer.php 
    Vendor ( 'the SMTP' );
     $ Mailer = new new PHPMailer ();

    //邮件配置
    $mailer->SetLanguage('zh_cn');
    $mailer->Host = $emailHost;
    //$mailer->Port = $emailPort;
    $mailer->SMTPSecure = 'ssl';
    $mailer->Port = 465;
    $mailer->Timeout = $emailTimeout;
    $mailer->ContentType = 'text/html';//设置html格式
    $mailer->SMTPAuth = true;
    $mailer->Username = $emailUserName;
    $mailer->Password = $emailPassword;
    $mailer->IsSMTP();
    $mailer->From = $mailer->Username; // 发件人邮箱
    $mailer->FromName =$emailFormName;
    $mailer->AddReplyTo( $mailer->Username );
    $mailer->CharSet = 'UTF-8';

    // 发送邮件
    $mailer->AddAddress( $toemail );
    $mailer->Subject = $subject;
    $mailer->Body = $message;
    if ($mailer->Send() === true) {
        return true;
    } else {
        $error = $mailer->ErrorInfo;
        return false;
    }
}

 

3 then write a call this function inside the controller

 public function testmail()
 {
     
     Email $ = 'recipient's e-mail address' ;
      $ title = 'test of title' ;
      $ Content = 'content testing, support html format' ;
     email($email,$title,$content);
 }

 

Guess you like

Origin www.cnblogs.com/baker95935/p/11002227.html