在sae平台上使用wordpress邮件功能的步骤:
1.用户创建wordpress应用后,在插件列表选择启用wp-mail-smtp,此时设置里表出现Email选项,
2.点击Email进入具体设置页面,选择使用smtp方式发送,3.在设置->Email->SMTP Host和设置->Email->SMTP Port设置项填写第三方SMTP服务器地址和开放端口(QQ测试可用
4.不要使用默认的localhost
使用QQ邮箱服务器,配置如下:
设置->Email->Mailer->勾选使用SMTP
设置->Email->SMTP Host->填写smtp.qq.com(所用服务器域名)
设置->Email->SMTP Host->填写465(所用服务器开放端口)
设置->Email->Encryption>使用SSL加密
设置->Email->Authentication>使用SMTP权限
设置->Email->Username>QQ邮箱全名
设置->Email->Password>QQ邮箱密码
关于不能使用mail函数和不能使用默认配置的说明:
1.关于勾选使用PHPmail方式发送邮件失败,提示mail()无法实例化的问题:
sae平台可能是出于性能以及防止垃圾邮件等考虑因素,禁止了mail()函数的直接使用,当在WordPress应用中设置发送邮件方式为使用 PHPmail时,就会无法实例化,
测试步骤:
我在sae 上传一个测试文件内容如下
$mail = new SaeMail();
$ret =$mail->quickSend(' ','Test2','ContentTest','......@qq.com'[Email],'.....'[passowrd]);
if($ret == false){
var_dump($mail->errno(),$mail->errmsg());
}
else{
var_dump($mail->errno(),$mail->errmsg());
echo "<br>OK<br>";
}
echo "PHP mail()Test<br>";
$text = "Test Email from PHP mail() function!";
mail(' ',$text);
?>
输出如下
int(0) string(2) "OK"
OK
PHP mail()Test
Warning: mail() has been disabled for security reasons in test1.php on line 39
结果:使用SAE平台接口SaeMail可以成功发送邮件,但是使用PHP本身的mail则被禁止,如果想要自己在代码中发送邮件,最好使用平台 提供的接口,具体可参考平台接口文档说明,如果不能满足要求,建议直接使用curl扩展,SaeMail本身使用curl扩展实现,所以该扩展可 以正常在sae上工作。
2.勾选了使用smtp方式发送邮件,使用默认配置(localhost)后仍然发送失败,并提示调用mail失败而不是wp_mail的原因
正常情况,勾选smtp方式后,使用默认设置(localhost),则调用插件本身重写的wp_mail函数,避免了mail函数的调用,但是 即使是能够正常调用wp_mail,因为wp-mail-smtp不是针对sae平台所写,所以不能保证wp_mail可以在sae平台上使用, 所以无论wp_mail能否被正常调用,都不建议使用默认配置,使用第三方邮件服务器,则可以正常工作。
错误提示中出现仍然调用mail函数而不是wp_mail的,可能是
i、由于正在使用的其他插件源码中调用了mail函数
插件作者是这样解释的:
= My plugin still sends mail via the mail() function =
If other plugins you're using are not coded to use the wp_mail() function but instead call PHP's mail() function directly, they will bypass the settings of this plugin. Normally, you can edit the other plugins and simply replace the `mail(` calls with `wp_mail(` (just adding wp_ in front) and this will work. I've tested this on a couple of plugins and it works, but it may not work on all plugins.
即需要修改其他所有插件源码,统一调用wp_mail