我正在开发一个 WordPress 插件,其中使用 PHP 邮件功能发送电子邮件,但邮件功能有问题。它会将电子邮件发送到我的非 Gmail 帐户,但不会将电子邮件发送到我的 Gmail 帐户。我正在使用以下代码:
function send_mail()
{
global $wpdb;
$to = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="761b0f1b171f1a36111b171f1a5815191b" rel="noreferrer noopener nofollow">[email protected]</a>';
$subject = 'Hello';
$name='my name';
$from="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3a545b575f7a57435e55575b535414595557" rel="noreferrer noopener nofollow">[email protected]</a>";
$message = "
<html>
<head>
<title>my title</title>
</head>
<body>
<div>
<tt> ".Hii How Are you."</tt>
</div>
</body>
</html>";
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset=iso-8859-1\r\n";
$header .= "From: ".$name."<".$from.">\r\n";
mail($to, $subject, $message, $header);
}
是我的代码有问题,还是邮件功能有问题?如果有任何替代方法可以发送电子邮件,请给我链接。
最佳答案
检查添加第五个变量是否适合您...这是我用于发送电子邮件的代码。
if( mail( $recipient, $subject, $message, $headers, "-f <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9cf2f3eef9ecf0e5dcf1e5f8f3f1fdf5f2b2fff3f1" rel="noreferrer noopener nofollow">[email protected]</a>"))
return "success";
关于PHP邮件功能无法向Gmail帐户发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19852615/