联系表格说成功但不发送电子邮件

时间:2015-05-30 23:39:29

标签: php forms email attachment contact

我有一个允许用户上传附件的联系表单。它很奇怪,因为当我使用联系表单时,会显示成功消息,但是当我查看我的电子邮件时,我的收件箱或垃圾邮件文件夹中都没有收到任何内容。但是,我附加到消息DO的文件出现在我的/ 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>

1 个答案:

答案 0 :(得分:1)

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

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

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

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

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

根据我的经验,Gmail对于接收电子邮件非常挑剔。过去,如果你没有正确的标题,那么电子邮件就会落入垃圾邮件文件夹,但现在我已经看到它改为Gmail根本不接受电子邮件的地方。

您可以通过Google搜索“php mail to spam gmail”之类的内容找到大量有关此内容的信息,因为过去电子邮件始终至少会转到垃圾邮件文件夹。不幸的是,问题比仅正确设置标题更复杂,您的电子邮件服务器配置以及随之而来的所有内容也必须正确。

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

sending email via php mail function goes to spam