问题描述
我需要为WordPress网站使用自定义SMTP设置,以通过电子邮件服务器(例如Mailgun或SendGrid)发送电子邮件。
解决方法
将其放置在主题function.php或您自己的插件中。
add_action( 'phpmailer_init','custom_phpmailer_init' );
function custom_phpmailer_init( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.mailgun.com';
$phpmailer->Port = 465;
$phpmailer->Username = 'user_name';
$phpmailer->Password = '********';
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = 'ssl';
$phpmailer->From = '[email protected]';
$phpmailer->FromName = 'FromName';
}