【问题标题】:Contact Form Says Successful But Not Sending The Email [duplicate]联系表显示成功但未发送电子邮件[重复]
【发布时间】:2015-05-30 23:39:28
【问题描述】:

我有一个允许用户上传附件的联系表。这很奇怪,因为当我使用联系表格时,会出现成功消息,但是当我检查我的电子邮件时,我的收件箱或垃圾邮件文件夹中什么也没有。但是,我附加到消息的文件确实出现在我的 /upload 文件夹中,因此该部分似乎工作正常。

只是我没有收到任何消息或任何东西。我不确定出了什么问题。代码粘贴在下面。

 <?



 if($_SERVER['REQUEST_METHOD'] == "POST")      {                                                            
$allowedExts = array("gif", "jpeg", "jpg", "png", "doc", "pdf", "docx",  "jpg", "docx", "odt", "txt", "msg", "csv", "pps", "ppt", "pptx", "xml", "tar", "m4a", "mp3", "wav", "wma", "mp4", "mov", "flv", "exe");


 for ($i = 1; $i <= 2; $i++) {
 $temp = explode(".", $_FILES["attach".$i]["name"]);
 $extension = end($temp);
 if (in_array($extension, $allowedExts)) {
  move_uploaded_file($_FILES["attach".$i]["tmp_name"],
  "upload/" .$_POST["firstname"]."-".$_FILES["attach".$i]["name"]);
 }
 }

 $to      = 'myemail@gmail.ca';
 $subject = 'Consultation from '.$_POST["firstname"];
 $message = $_POST["message"]."\n\n\n Attachments: ".$_FILES["attach1"]["firstname"]." ".$_FILES["attach2"]["firstname"]." ".$_FILES["attach3"]["firstname"];
  $firstname=$_REQUEST['firstname'];
  $companyname=$_REQUEST['companyname'];
  $email=$_REQUEST['email'];

  if (($firstname=="")||($email=="")||($message=="")) 
     { 
     echo "<strong><p class =greentip>A first name, message, and email   are required, please fill <a href=/consult.php>the form</a> again.</p></strong><br>"; 
    } 
  else{ 
   mail($to, $subject, $message, $firstname, $email);
 echo "<strong><p class = greentip>Your free consultation request has    been received! Expect a detailed response within the next 3 hours.</p></strong>"; 
    }
  }
  ?>

   <form  action="" method="post" enctype="multipart/form-      data">                       

<strong>First Name *</strong><br> 
<input name="firstname" type="text" value=""><br>

<strong>Company Name </strong><br> 
<input name="companyname" type="text" value=""><br>


<strong>Email *</strong><br> 
<input name="email" type="text" value=""<br> 

<strong>Your message *</strong><br> 
<textarea name="message" rows="7" cols="30" placeholder="In your query, include any and all revelant information pertaining to the nature of your writing request. The more specific you are in your request, the more complete we will be in our response!"></textarea><br> 

<strong>Attachments</strong><br> 

   <input name = "attach1" type="file" class="file" />

  <br> 

     <input name = "attach2" type="file" class="file" />

  <br><br>
   <center><input type="submit" value="submit"></center> <br>
    </form>

【问题讨论】:

  • 你是在本地运行还是在服务器上运行?你有安装邮件服务器吗?
  • mail 函数的最后一个(第五个)参数用于附加命令行选项,php.net/manual/en/function.mail.php。您是否尝试在那里发送From 标头?尝试将mail 也放入条件中,以便确认它失败了。
  • 地址,我没有安装邮件服务器。但是,我的另一张联系表格使用完全相同的代码,但没有附件,而且效果很好。

标签: php forms email attachment contact


【解决方案1】:

编辑:您错误地使用了mail() 函数。该函数接受:

mail($to, $subject, $message, $optional_headers, $optional_additional_params);

您尝试通过$firstname$email 的方式是错误的。请see the docs

================================================ ======================

php mail() 函数非常基础。它返回一个表示成功的布尔值,但即使它返回 true,也有很多事情可能出错,阻止mail() 不知道的电子邮件传递。

根据我的经验,Gmail 对接收电子邮件非常挑剔。过去,如果您没有正确的标题,电子邮件只会进入垃圾邮件文件夹,但现在我看到它变成了 Gmail 根本不接受电子邮件的地方。

您可以通过谷歌搜索诸如“php 邮件转到垃圾邮件 gmail”之类的内容来找到很多关于此的信息,因为过去电子邮件总是至少进入垃圾邮件文件夹。不幸的是,问题不仅仅是正确设置标题更复杂,您的电子邮件服务器配置以及随之而来的所有事情也必须恰到好处。

https://serverfault.com/questions/449244/php-mail-to-gmail-spam

sending email via php mail function goes to spam

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-02
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    • 2023-03-28
    • 1970-01-01
    相关资源
    最近更新 更多