我在这里创建了一个带有文件附件的简单 PHP 电子邮件报价请求表 http://www.cmipromotions.com/upload-file-test-form/ 当我提交带有附件的表单时,通常会向收件人发送一封电子邮件,但电子邮件没有文件附件。我没有收到任何错误消息。这是表单 HTML 代码:
<div style="background-image: url('/images/cmi_horizontal_quote_request_form_bg_slim.gif'); background-repeat: no-repeat; height: 227px; width: 520px; margin-right:auto; margin-left:auto;"><form action="../contact-form-handlerUpload.php" method="POST" name="contactform" enctype="multipart/form-data">
<table style="width: 520px;">
<tbody>
<tr>
<td style="width: 280px;">
<p style="margin-bottom: 10px; text-align: center; padding-top: 50px;"><input id="mattfield" style="font-size: 12px; padding: 2px 5px; width: 200px;" onfocus="if (this.value=='Name') this.value='';" onblur="if (this.value=='') this.value='Name';" type="text" name="name" value="Name" /></p>
<p style="margin-bottom: 10px; text-align: center;"><input id="mattfield" style="font-size: 12px; padding: 2px 5px; width: 200px;" onfocus="if (this.value=='Email') this.value='';" onblur="if (this.value=='') this.value='Email';" type="text" name="email" value="Email" /></p>
<p style="margin-bottom: 10px; text-align: center;"><input id="mattfield" style="font-size: 12px; padding: 2px 5px; width: 200px;" onfocus="if (this.value=='Company') this.value='';" onblur="if (this.value=='') this.value='Company';" type="text" name="company" value="Company" /></p>
<p style="margin-bottom: 10px; text-align: center;"><input id="mattfield" style="font-size: 12px; padding: 2px 5px; width: 200px;" onfocus="if (this.value=='Phone') this.value='';" onblur="if (this.value=='') this.value='Phone';" type="text" name="phone" value="Phone" /></p>
<p style="text-align: center;"><textarea style="width:200px; max-width: 200px; height: 25px; max-height:30px; border-width: 0.5px;" name="message"></textarea></p>
</td>
<td style="width: 280px;">
<p style="margin-bottom: 10px; text-align: center; padding-top: 14px;"><input id="mattfield" style="font-size: 12px; padding: 2px 5px; width: 200px;" onfocus="if (this.value=='Product#') this.value='';" onblur="if (this.value=='') this.value='Product#';" type="text" name="product" value="Product#" /></p>
<p style="margin-bottom: 10px; text-align: center;"><input id="mattfield" style="font-size: 12px; padding: 2px 5px; width: 200px;" onfocus="if (this.value=='Quantity (100pc min)') this.value='';" onblur="if (this.value=='') this.value='Quantity (100pc min)';" type="text" name="quantity" value="Quantity (100pc min)" /></p>
<p style="margin-bottom: 10px; text-align: center;"><input id="mattfield" style="font-size: 12px; padding: 2px 5px; width: 200px;" onfocus="if (this.value=='Upload File') this.value='';" onblur="if (this.value=='') this.value='Upload File';" type="file" multiple="false" name="uploadfile" value="Upload File" /></p>
<div style="color: black; margin-bottom: 10px; text-align: center; margin-right: auto; margin-left: auto; width: 130px;">
<table>
<tbody>
<tr>
<td>Capacity</td>
<td><select id="capacity" name="capacity"> <option style="padding-bottom: 2px;" selected="selected" value="1GB">1GB</option> <option style="padding-bottom: 2px;" value="2GB">2GB</option> <option style="padding-bottom: 2px;" value="4GB">4GB</option> <option style="padding-bottom: 2px;" value="8GB">8GB</option> <option style="padding-bottom: 2px;" value="16GB">16GB</option> <option style="padding-bottom: 2px;" value="32GB">32GB</option><option style="padding-bottom: 2px;" value="64MB">64MB</option><option style="padding-bottom: 2px;" value="128MB">128MB</option><option style="padding-bottom: 2px;" value="256MB">256MB</option> <option style="padding-bottom: 2px;" value="512MB">512MB</option> </select></td>
</tr>
</tbody>
</table>
</div>
<center><input id="mattcool" style="background-image: url('/images/CMI_horizontal_quote_button3.gif'); height: 37px; border: 0px none; width: 178px; position: inherit; transition: none;" type="submit" value="" /></center></td>
</tr>
</tbody>
</table>
</form><script type="text/javascript" language="JavaScript">// <![CDATA[
// Code for validating the form // Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml // for details var frmvalidator = new Validator("contactform"); frmvalidator.addValidation("name","req","Please provide your name"); frmvalidator.addValidation("email","req","Please provide your email");
// ]]></script>
</div>
<br>
这是php
<?php
$errors = '';
$myemail = 'myaddress@myaddress.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']))
{
$errors .= "\n Error: Name & Email are required";
}
$random_hash = md5(date('r', time()));
//*** Attachment ***//
if($_FILES["uploadfile"]["name"] != "")
{
$strFilesName = $_FILES["uploadfile"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["uploadfile"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$company = $_POST['company'];
$phone = $_POST['phone'];
$product = $_POST['product'];
$quantity = $_POST['quantity'];
$capacity = $_POST['capacity'];
$message = $_POST['message'];
$pagetitle = $_POST['pagetitle'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "New Inquiry Form Submission from: $name";
$email_body = "You have received a new lead from the $pagetitle page \n Here are the details:\n Name: $name \n Company: $company \n Email: $email_address \n Phone Number: $phone \n Product #: $product \n Page Title: $pagetitle \n Quantity: $quantity \n Capacity: $capacity \n Message: \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
$spam_error_message = "No SPAM Permitted";
if (preg_match("/http/i", "$name")) {echo "$spam_error_message"; exit();}
if (preg_match("/http/i", "$email_address")) {echo "$spam_error_message"; exit();}
if (preg_match("/http/i", "$company")) {echo "$spam_error_message"; exit();}
if (preg_match("/http/i", "$phone")) {echo "$spam_error_message"; exit();}
if (preg_match("/http/i", "$message")) {echo "$spam_error_message"; exit();}
if (preg_match("/http/i", "$product")) {echo "$spam_error_message"; exit();}
if (preg_match("/http/i", "$quantity")) {echo "$spam_error_message"; exit();}
if (preg_match("/http/i", "$capacity")) {echo "$spam_error_message"; exit();}
if (preg_match("/www/i", "$name")) {echo "$spam_error_message"; exit();}
if (preg_match("/www/i", "$email_address")) {echo "$spam_error_message"; exit();}
if (preg_match("/www/i", "$company")) {echo "$spam_error_message"; exit();}
if (preg_match("/www/i", "$phone")) {echo "$spam_error_message"; exit();}
if (preg_match("/www/i", "$message")) {echo "$spam_error_message"; exit();}
if (preg_match("/www/i", "$product")) {echo "$spam_error_message"; exit();}
if (preg_match("/www/i", "$quantity")) {echo "$spam_error_message"; exit();}
if (preg_match("/www/i", "$capacity")) {echo "$spam_error_message"; exit();} if (preg_match("/katieskittles/", "$email_address")) {echo "$spam_error_message"; exit();}
mail($to,$email_subject,$email_body,$headers,$strHeader);
mail($email_address,"Thank you for contacting CMI Promotions","Thank you for contacting CMI Promotions.\nYour request has been received and we will respond to you shortly. \nOur normal business hours are M-F 8:30 am to 5:00 pm PST. \nAll Inquiries received on weekends or after hours will be addressed the following business day. \nYou are also welcome to contact us directly at 855-463-3080 if you need immediate assistance.",$headers);
//redirect to the 'thank you' page
header('Location: http://www.cmipromotions.com/thank-you-for-your-inquiry/');
}
?>
您能给我的任何帮助将不胜感激!