如何使用 PHP 在 WordPress 中发送电子邮件
对于初学者,我下载了一个WordPress插件,该插件使您可以将PHP片段插入WordPress站点。我添加了此代码,希望它将发送电子邮件,但我还没有收回任何内容。我使用了两个不同的摘要插件,我不确定会导致问题的原因,或者是否有一种更简单的方法可以进行此操作。
<?php
$to = '[email protected]';
$subject = 'Test email';
$message = 'Test';
$headers = "From: The Sender name <[email protected]>";
mail($to, $subject, $message, $headers);
?>
For starters, I downloaded a Wordpress plugin that allows you to insert PHP snippets into a Wordpress site. I added this code hoping that it will send an email but I have not receeved anything yet. I have used two different snippet plugins, and I am not sure what could be causing the issue, or if there would be an easier way to go about doing this.
<?php
$to = '[email protected]';
$subject = 'Test email';
$message = 'Test';
$headers = "From: The Sender name <[email protected]>";
mail($to, $subject, $message, $headers);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用wp_mail。
wp_mail
的好处是它使用 WordPress 中配置的默认邮件传递服务。值得注意的是,默认的 PHP 邮件程序在本地计算机上运行时不太可能工作。
我建议为 WordPress 设置一个邮件插件,该插件使用 Mailgun 等第三方邮件服务来发送电子邮件。我使用WP Mail SMTP
You can use wp_mail. The good thing about
wp_mail
is that it uses whatever the default mail delivery service is configured in WordPress.It's worth noting that the default PHP mailer is unlikely to work when running on your local machine.
I recommend setting up a mail plugin for WordPress that uses a third-party mail service like Mailgun to send emails. I use WP Mail SMTP