PHP的邮件()函数无法正常工作
问题描述:
我使用PHP的mail()函数从我的网站发送自动电子邮件,并在测试时发现,当我通过Gmail从网站发送邮件时,电子邮件由PHP邮件发送正在收件人端产生以下警告:此消息可能不会发送:[email protected]了解更多举报网络钓鱼。但是,当我使用其他电子邮件(如雅虎,Outlook),然后我没有收到我的$ contact_email电子邮件。请帮我解决这个问题。PHP的邮件()函数无法正常工作
**我不想使用Google应用。和我的域名电子邮件地址。 **我只是想要如果有人联系(填写表格),然后我刚刚在我的网站上收到电子邮件。 下面的代码:
<?php
global $_REQUEST;
$response = array('error'=>'');
$user_name = substr($_REQUEST['user_name'], 0, 20);
$user_email = substr($_REQUEST['user_email'], 0, 40);
$user_msg = $_REQUEST['user_msg'];
$contact_email = '[email protected]';
if (trim($contact_email)!='') {
$subj = 'Message from Official Website';
$msg = "Name: $user_name
E-mail: $user_email
Message: $user_msg";
$head = "Content-Type: text/plain; charset=\"utf-8\"\n"
. "X-Mailer: PHP/" . phpversion() . "\n"
. "Reply-To: $user_email\n"
. "To: $contact_email\n"
. "From: $user_email\n";
if ([email protected]($contact_email, $subj, $msg, $head)) {
$response['error'] = 'Error send message!';
}
} else
$response['error'] = 'Error send message!';
echo json_encode($response);
die();
?>
答
周围有没有办法和谷歌所做的只是防止SAPM。尝试从'[email protected]'发送'reply-to'作为您的gmail。你的域名应该是你发送的网站所在的域名。
另一方面,我还建议使用一个封装邮件函数的库,看看SwiftMailer。
+0
如何在'reply-to'中添加gmail?你能帮我写这个吗? – 2014-09-18 20:12:49
您发送的电子邮件地址不是官方Gmail地址。 Google随后会标记您的电子邮件以模仿他们。雅虎/ Outlook可能会自动删除电子邮件。 – Grice 2014-09-18 19:53:58
如果它只是一个联系表单,难道你不能只使用提交给'mailto'的HTML表单吗? – muttley91 2014-09-18 19:54:46