php 发送smtp邮件

时间:2022-05-19 18:08:32
需要下载PHPMailer/PHPMailerAutoload.php这个类。调用如下:

<?php
 $id = 1105;
 $fromName = '张三';
 $html = '测试内容';
 $subject = '测试标题';
 $toMail = '2256285375@qq.com';
 $replyTo = '925546266@qq.com';
 $from = 'qqsanji@info.mailufo.com';
 require_once 'PHPMailer/PHPMailerAutoload.php';
 $mail = new \PHPMailer;
 $mail->Charset = 'utf-8';
 $mail->Encoding = 'base64';
 $mail->isSMTP();
 $mail->Host = '';//ip保密
 $mail->Port = 25;
 $mail->SMTPAuth = true;
 $mail->Username = '';//账号保密
 $mail->Password = 'f2409d3b';
 if (!empty($filePath) && file_exists(ROOT_PATH . $filePath)) {
  $mail->AddAttachment(ROOT_PATH . $filePath, $file_name);
 }
 $mail->AddCustomHeader('X-Scedm-Tid', $id);
 $mail->Sender = $from;
 $mail->setFrom($from, "=?utf-8?B?" . base64_encode($fromName) . "?=");
 $mail->addAddress($toMail);
 $mail->addReplyTo($replyTo, "=?utf-8?B?" . base64_encode($fromName) . "?=");
 $mail->isHTML(true);
 $mail->Subject = "=?utf-8?B?" . base64_encode($subject) . "?=";
 $mail->MsgHTML(htmlspecialchars_decode(htmlspecialchars_decode($html)));
 $mail->AltBody = '';
 $a = $mail->send();
 var_dump($a);
 //smtp表密码userinfo_edm_trigger
 if(!$a){
  $msg = $mail->ErrorInfo;
  var_dump($msg);
 }