我是wordpress的新手。我通过wp-mail功能在本地发送邮件,我已经为smtp安装了east wp-mail插件。
include("wp-mail.php");
$to = 'test@gmail.com';
$subject = 'Apple Computer';
$message = 'Steve, I think this computer thing might really take off.';
wp_mail( $to, $subject, $message );
但我得到了错误liike:
慢一点,牛仔,没必要这么频繁地查看新邮件!
请引导我…
我需要更改任何文件或安装任何插件吗???
wp_mail
的工作原理类似于PHP的函数mail
。你可以在这里阅读更多关于它的信息。PHP mail
函数需要访问sendmail
二进制文件,正如文档中所述,您不应该在localhost中配置它,这就是它无法发送电子邮件的原因。
为了在本地主机中测试您的站点时发送电子邮件,您应该将SMTP配置为发送电子邮件。
有一个很好的插件叫做WP-MailSMTP,你可以在这里安装它。
它覆盖了wp_mail
功能,使您能够使用Gmail SMTP服务器发送电子邮件。您可以使用任何需要的SMTP服务器。
如果你不想使用任何插件来设置smtp,你可以用代码轻松完成。WordPress有自己的挂钩来设置smtp。
这是代码。只需添加您的主机、用户名和密码。您可以从本地机器发送电子邮件。
add_action( 'phpmailer_init', 'my_phpmailer_example' );
function my_phpmailer_example( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.example.com';
$phpmailer->SMTPAuth = true; // Force it to use Username and Password to authenticate
$phpmailer->Port = 25;
$phpmailer->Username = 'yourusername';
$phpmailer->Password = 'yourpassword';
// Additional settings…
//$phpmailer->SMTPSecure = "tls"; // Choose SSL or TLS, if necessary for your server
//$phpmailer->From = "you@yourdomail.com";
//$phpmailer->FromName = "Your Name";
}
您可以在WordPress Codex 上了解更多信息