【发布时间】: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