【问题标题】:gmail ignoring emails from a php contact formgmail忽略来自php联系表格的电子邮件
【发布时间】:2012-11-10 00:55:51
【问题描述】:

我们在网站上使用 php 电子邮件表单,它在向其他电子邮件程序发送电子邮件时工作正常,只是不是 gmail,我检查了垃圾邮件和收件箱,但我什么也没收到,好像 gmail 不信任电子邮件并且完全忽略它。我们怎样才能让他们通过?

我用于表单的代码是:

<div id="contact-form">
<form id="commentForm" action="assets/php/mail.php" method="POST">
<input type="text" name="name" class="required" placeholder="Name..">

<input type="text" name="email" class="required email" placeholder="Email..">

<input type="text" name="phone" class="required" placeholder="Phone..">

<textarea name="message" placeholder="Message.." class="required"></textarea><br />

<input class="subm" type="submit" value="Submit..">
</form>
</div>

而php是

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Contact Form Confirmation</title>

<meta http-equiv="refresh" content="4; url=http://www.domain.co.uk">
</head>

<body>

<?php $name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent="
<h1>From :</h1> $name \n
<h1>Email :</h1> $email \n
<h1>Phone :</h1> $phone \n 
<h1>Message :</h1> $message
";

$recipient = "studio@domain.co.uk";
$subject = "Contact Form";
$mailheader = "MIME-Version: 1.0" . "\r\n";
$mailheader .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$mailheader .= "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

echo("<p>Thanks for getting in touch, we'll get back to you shortly..</p>");
?>

</body>
</html>

【问题讨论】:

  • 也许为 $formcontent 构建有效的 HTML 会有所帮助?你试过添加&lt;html&gt;&lt;/html&gt;和&lt;body&gt;&lt;/body&gt;吗?
  • 他们不是已经在里面了吗? html 打开第 2 行,body 打开第 10 行,关闭最后 2 行?
  • 它们存在于您向用户显示的文档中,但不在 $formcontent 中!但是,更重要的是检查 TheSmose 的答案,他可能有你要找的东西!

标签: php forms email gmail html-email


【解决方案1】:

GMail 不是唯一会忽略 sendmail 电子邮件的邮件服务。

原因很可能是您的 From: 标头与您的邮件服务器主机名不匹配。如果您使用的是 3rd-party 托管,您应该找出主机名(例如“myhost.com”)并在 From: 标头中使用它。然后在“回复”标题中使用正确的电子邮件地址。

$mailheader .= "Reply-To: Some One <someone@mydomain.com>\r\n"; 
$mailheader .= "Return-Path: Some One <someone@mydomain.com>\r\n"; 
$mailheader .= "From: Some One <mydomain@myhost.com>\r\n"; 
$mailheader .= "Organization: My Organization\r\n"; 
$mailheader .= "Content-Type: text/plain\r\n"; 

为了提高送达率,您应该使用 SMTP 通过实际的电子邮件帐户发送邮件。

要绝对最大化可交付性,您应该使用 ESP。

【讨论】:

    【解决方案2】:

    另一种(更简单)的可能性...尝试使用 -f 选项:

    mail($recipient, $subject, $formcontent, $mailheader, "-f {$email}") or die("Error!");
    

    【讨论】:

    • 感谢您的回复,您能告诉我 -f 选项的优缺点吗? smtp 电子邮件也是使用服务器端脚本完成的吗?
    【解决方案3】:

    我刚刚在这里回答了一个类似的问题:

    Sending via email info from a contact form with PHP

    只需检查一下,我相信它包含解决问题所需的所有代码,至少在您不期望大量电子邮件的情况下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多