WordPress SMTP发送邮件及前台发邮件

wordpress 前台发送邮件

1.修改使用SMTP发送邮件
最近在使用wodpress给公司制作一个网站需要在前台联系我们页面添加发送邮件到指定邮箱功能.
在网上查了很多插件都没有这个功能(应该是我不会用),后面就自己动手开始写代码.
在网上查了很多资料都是老版本的而且千篇一律代,码如下:

//smtp发送邮件功能
add_action('phpmailer_init', 'mail_smtp');
function mail_smtp( $phpmailer ) {
$phpmailer->FromName = ''; //名字
$phpmailer->Host = ''; //smtp地址,可以到你使用的邮件设置里面找
$phpmailer->Port = 465; //端口,一般不用修改
$phpmailer->Username = '';  //邮件账号
$phpmailer->Password = ''; //邮件密码
$phpmailer->From = '';//邮件账号
$phpmailer->SMTPAuth = true;  
$phpmailer->SMTPSecure = 'ssl'; //tls or ssl (port=25留空,465为ssl)一般不用修改
$phpmailer->IsSMTP();
}

这个代码说需要添加到functions.php文件里
ps.这个店面我没有测试!新版本已经集成了smtp邮件功能就比较简单了,不要修改wordpress源码.

//SMTP邮箱设置
function mail_smtp($phpmailer) {
    $phpmailer->From = ''; //发件人地址
    $phpmailer->FromName = ''; //发件人昵称
    $phpmailer->Host = ''; //SMTP服务器地址
    $phpmailer->Port = ''; //SMTP邮件发送端口
    $phpmailer->SMTPSecure = '';//SMTP加密方式(SSL/TLS)没有为空即可
    $phpmailer->Username = ''; //邮箱帐号
    $phpmailer->Password = ''; //邮箱密码
    $phpmailer->IsSMTP();
    $phpmailer->SMTPAuth = true; //启用SMTPAuth服务
}
add_action('phpmailer_init', 'mail_smtp');

此代码需要添加到functions.php文件里
我们只需要添加一个函数然后添加动作到”phpmailer_init”这样就可以使用SMTP功能了.

2.在前台发送邮件
我们先来建个页面模板mail.php






教程到此结束有什么不懂的可以留言

参考资料

wp_mail()

未经允许不得转载:窗外天空 » WordPress SMTP发送邮件及前台发邮件

赞 (0)

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址