WordPress 代码配置 SMTP 邮件发送功能

将下面代码中信息修改为自己信息,放进主题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

TLS(Transport Layer Security)和SSL(Secure Sockets Layer)都是用于加密数据传输的安全协议。它们在不同版本中存在一些差异,SSL是TLS的前身,而TLS是SSL的升级版本。

一般情况下,使用TLS是更好的选择,特别是TLS 1.3,因为它提供了更高的安全性和性能。但请注意,具体选择应取决于您的服务器和客户端的支持情况以及安全需求。要确保与您的SMTP服务器的要求和最佳实践保持一致。

邮箱 SMTP 服务器地址 非 SSL 端口号 SSL 端口号
163.com smtp.163.com 25 465 或 994
126.com smtp.126.com 25 465 或 994
qq.com smtp.qq.com 25 465 或 587
网易企业邮箱 smtp.qiye.163.com 25 994
腾讯企业邮箱 smtp.exmail.qq.com 25 465
阿里企业邮箱 smtp.qiye.aliyun.com 25 465 或 587

给TA打赏
共{{data.count}}人
人已打赏
未分类

WordPress 代码配置 SMTP 邮件发送功能

2025-1-19 12:49:31

未分类

WordPress 代码配置 SMTP 邮件发送功能

2025-1-19 12:49:31

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
搜索