话不多说,根据官方dome修改下,官方更新地址:https://github.com/PHPMailer/PHPMailer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'PHPMailer/Exception.php' ; require 'PHPMailer/PHPMailer.php' ; require 'PHPMailer/SMTP.php' ; date_default_timezone_set( 'PRC' ); //设置邮件发送的时间,如果不设置,则会显示其他区的时间 $mail = new PHPMailer(true); // Passing `true` enables exceptions try { //服务器设置 // 0 = off (for production use) // 1 = client messages // 2 = client and server messages // 是否启用smtp的debug进行调试 开发环境建议开启 生产环境注释掉即可 默认关闭debug调试模式 $mail ->SMTPDebug = 2; $mail ->isSMTP(); // 使用SMTP协议进行发送 $mail ->Host = 'smtp.exmail.qq.com' ; // SMTP 邮箱服务器 $mail ->SMTPAuth = true; // SMTP验证开启 $mail ->Username = 'service@ibang114.com' ; // 用户名,一般填发件箱 $mail ->Password = '' ; // 邮箱密码 $mail ->SMTPSecure = 'SSL' ; // Enable TLS encryption, `ssl` also accepted $mail ->Port = 25; // SMTP端口 //收件人 $mail ->setFrom( 'service@ibang114.com' , '南昌大学圈' ); // 设置发件人邮箱地址 $mail ->addAddress( '123456789@qq.com' , '尊敬的客户' ); // 设置收件人邮箱地址 //内容 $mail ->isHTML(true); // 将电子邮件格式设置为 HTML $mail ->CharSet = 'UTF-8' ; $mail ->Subject = '静夜思' ; //邮件的主题 $mail ->Body = '床前明月光<br />疑是地上霜<br />举头望明月<br />低头思故乡<br />' ; //邮件的内容 $mail ->send(); echo '邮件已发送' ; } catch (Exception $e ) { echo '无法发送邮件。邮件错误: ' , $mail ->ErrorInfo; } ?> |