设置smtp
function site_smtp( $phpmailer ) {
$phpmailer->Mailer = 'smtp';
$phpmailer->Host = 'smtp.163.com';//邮件服务器地址
$phpmailer->SMTPAuth = true;
$phpmailer->Port = '465';//邮件服务器端口
$phpmailer->SMTPSecure = 'ssl';
$phpmailer->Username = '***********';//授权用户名
$phpmailer->Password = '***********';//授权密码
$phpmailer->From = '*************';//设置发件人邮箱地址
// try {
// $phpmailer->Send();
// } catch ( phpmailerException $e ) {
// echo $phpmailer->ErrorInfo;
// }
}
//配置后用wp_mail函数发送邮件
add_action( 'phpmailer_init', 'site_smtp', 10);
$headers = ['Content-Type: text/html; charset=UTF-8'];
$mailSent = wp_mail($_POST['email'], '', $message, $headers);