59 lines
1.3 KiB
PHP
59 lines
1.3 KiB
PHP
<?php
|
||
include './cgp.php';
|
||
// 示例使用
|
||
|
||
|
||
// 引入 PHPMailer 的文件
|
||
require 'phpmailer/src/PHPMailer.php';
|
||
require 'phpmailer/src/SMTP.php';
|
||
require 'phpmailer/src/Exception.php';
|
||
use PHPMailer\PHPMailer\PHPMailer;
|
||
use PHPMailer\PHPMailer\Exception;
|
||
|
||
function sendMail($to,$subject,$content) {
|
||
|
||
|
||
$mail = new PHPMailer(true); // 实例化PHPMailer对象
|
||
|
||
try {
|
||
// 邮件服务器配置
|
||
$mail->isSMTP(); // 使用SMTP
|
||
$mail->Host = '127.0.0.1'; // SMTP服务器地址
|
||
$mail->Username = 'cloud@fuxsto.cn'; // SMTP用户名
|
||
$mail->Password = ''; // SMTP密码
|
||
|
||
$mail->SMTPAutoTLS = false; // 禁用自动TLS
|
||
$mail->SMTPSecure = ''; // 确保没有加密
|
||
|
||
$mail->Port = 25; // SMTP端口号
|
||
|
||
// 发件人和收件人
|
||
$mail->setFrom('cloud@fuxsto.cn', 'Fuxsto Mail'); // 发件人
|
||
$mail->addAddress($to, $to); // 收件人
|
||
|
||
// 邮件内容
|
||
$mail->isHTML(true); // 设置邮件格式为HTML
|
||
$mail->Subject = $subject;
|
||
$mail->Body = $content; // HTML格式的邮件内容
|
||
$mail->AltBody = $content; // 如果收件人客户端不支持HTML,则显示此内容
|
||
|
||
// 发送邮件
|
||
$mail->send();
|
||
return 200;
|
||
} catch (Exception $e) {
|
||
return "邮件发送失败,错误信息: {$mail->ErrorInfo}";
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|