main.php
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 44 45
| <?php use PHPMailer\\PHPMailer\\PHPMailer; use PHPMailer\\PHPMailer\\Exception;
require './src/Exception.php'; require './src/PHPMailer.php'; require './src/SMTP.php'; function sendEmail($content){ $mail = new PHPMailer(true); try { $mail->CharSet ="UTF-8"; $mail->SMTPDebug = 0; $mail->isSMTP(); $mail->Host = 'smtp.qq.com'; $mail->SMTPAuth = true; $mail->Username = 'xinhaojin@qq.com'; $mail->Password = 'tjhv*********xdjaj'; $mail->SMTPSecure = 'ssl'; $mail->Port = 465;
$mail->setFrom('xinhaojin@qq.com', '张三'); $mail->addAddress('xinhaojin@qq.com', '张三'); $mail->addReplyTo('xinhaojin@qq.com', '张三');
$mail->isHTML(true); $mail->Subject = '有新留言,请尽快审核!'; $mail->Body = '<h1>'.$content.'</h1>'; $mail->AltBody = $content;
$mail->send(); echo '邮件发送成功'; } catch (Exception $e) { echo '邮件发送失败: ', $mail->ErrorInfo; } } sendEmail('快来看看吧');
|
还需要一个src文件夹,内容如下
可以在GitHub下载https://github.com/PHPMailer/PHPMailer,下载后解压,只需要用到src文件夹
蓝奏云下载链接https://xinhaojin.lanzoui.com/izMoEqz9fyj