wordpress 设置 smtp 发邮件(无插件)
通过修改 functions.php 和 wp-config.php 配置 WordPress SMTP 邮件发送功能,无需安装任何插件
Copied
通过修改 functions.php 和 wp-config.php 配置 WordPress SMTP 邮件发送功能,无需安装任何插件
修改 WordPress 主题的 functions.php 文件,让 WordPress 使用 wp-config.php 里的 SMTP 设置:
function custom_smtp_settings($phpmailer) {
$phpmailer->isSMTP();
$phpmailer->Host = SMTP_HOST;
$phpmailer->SMTPAuth = SMTP_AUTH;
$phpmailer->Port = SMTP_PORT;
$phpmailer->SMTPSecure = SMTP_SECURE;
$phpmailer->Username = SMTP_USERNAME;
$phpmailer->Password = SMTP_PASSWORD;
$phpmailer->From = SMTP_FROM;
$phpmailer->FromName = SMTP_FROM_NAME;
}
add_action('phpmailer_init', 'custom_smtp_settings');
在 wp-config.php 文件中,添加以下代码(建议放在 /* That's all, stop editing! Happy publishing. */ 之前):
// SMTP 配置
define('SMTP_HOST', 'smtp.qq.com'); // SMTP 服务器地址
define('SMTP_PORT', 465); // SMTP 端口(常见端口:465(SSL),587(TLS))
define('SMTP_SECURE', 'ssl'); // 加密方式(ssl 或 tls)
define('SMTP_AUTH', true); // 是否需要身份验证
define('SMTP_USERNAME', 'your-email@qq.com'); // 邮箱地址
define('SMTP_PASSWORD', 'your-email-auth-code'); // 邮箱密码或授权码
define('SMTP_FROM', 'your-email@qq.com'); // 发件人邮箱
define('SMTP_FROM_NAME', 'Your Site Name'); // 发件人名称
define('SMTP_DEBUG', 0); // 调试模式(0 = 关闭,1 = 开启)
wordpress 设置 smtp 发邮件(无插件)
www.jsom.top/post/wordpress-设置-smtp-发邮件无插件
Comments