WordPress纯代码实现SMTP发送邮件

网站APP 4 个月前 回复

, ,

将下面代码中信息修改为自己信息,放进主题functions.php适当位置。

// 使用SMTP发送邮件
function custom_phpmailer_init( $phpmailer ) {
    $phpmailer->isSMTP(); // 告诉PHPMailer使用SMTP
    $phpmailer->Host       = 'smtp.example.com'; // SMTP服务器地址
    $phpmailer->SMTPAuth   = true; // 启用SMTP认证
    $phpmailer->Port       = 587; // SMTP端口(通常为587)
    $phpmailer->Username   = 'your_email@example.com'; // 您的邮箱账户
    $phpmailer->Password   = 'your_email_password'; // 您的邮箱密码或者授权码
    $phpmailer->SMTPSecure = 'tls'; // 使用TLS加密,也可以使用'ssl'
    $phpmailer->From       = 'your_email@example.com'; // 发件人邮箱地址
    $phpmailer->FromName   = 'Your Name'; // 发件人名称
}
add_action( 'phpmailer_init', 'custom_phpmailer_init' );

其中TLS端口是587,SSL端口465。

参考文章:https://www.feinews.com/54565.html

支付宝打赏微信打赏

如果此文对你有帮助,欢迎打赏作者。

发表评论

欢迎回来 (打开)

(必填)