Ok here is my issue, I wanna create multiple attachments for to send with my PHP contact form
Here is the HTML CODE: Which has the attachment box, but I want to create more in HTML and PHP. I am totally stumped
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Easy CE Marking - Contact Us</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
<script type="text/javascript" src="images.js"></script>
<script type="text/javascript">
function checkFields(){
if(document.forms[0].name.value == "" || document.forms[0].company.value == "" || document.forms[0].streetAddress.value == "" || document.forms[0].websiteAddress.value == "" || document.forms[0].emailAddress.value == "" || document.forms[0].city.value == "" || document.forms[0].state.value == "" || document.forms[0].zipCode.value == "" || document.forms[0].country.value == "" || document.forms[0].phone.value == "" || document.forms[0].description.value == "" || document.forms[0].comments.value == ""){
alert("Please fill out all text fields.");
return false;
}
}
</script>
<style type="text/css">
<!--
.checkboxes {font-weight: normal;
}
.checkboxes1 { font-weight: lighter;
text-align: center;
clip: rect(auto,auto,auto,85px);
word-spacing: normal;
letter-spacing: normal;
}
.content { padding: inherit;
}
.div {line-height:inherit;
}
.style1 {color: #FFFFFF}
.style2 {color: #000000}
-->
</style>
</head>
<body>
<div id="top">
<table id="nav" cellpadding="0" cellspacing="0">
<tr>
<td>
<a href="cemarking.html">WELCOME</a>
</td>
<td>
<a href="cedirectives.html">CE DIRECTIVES</a>
</td>
<td>
<a style="background: #FFFFFF; cursor: default" href="javascript:void(0)">CONTACT US</a>
</td>
</tr>
</table>
<img src="logo.jpg" style="float: left" alt=""/>
</div>
<div id="main">
<img src="arrow.png" class="arrow" alt=""/><h2>Contact Us</h2>
<p><br/>
Call 800-422-1651 to make an appointment with an Easy CE Marking representative, or send us an email using the form below. You should receive an auto-response email right after submitting the form. </p>
<p> </p>
<div><form enctype="multipart/form-data" action="contact.php" onsubmit="javascript: return checkFields()" method="post">
<fieldset>
<table cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
<h2 align="center">Contact Information</h2>
<div align="center">
<table cellpadding="0" cellspacing="0"><tr><td><table cellpadding="0" cellspacing="0">
<tr>
<td><table cellpadding="0" cellspacing="0">
<tr>
<td><div align="center" class="style1"><span class="style2">Name <br/>
<input name="name" id="sf" type="text"/>
<br/>
Company <br/>
<input name="company" type="text"/>
<br/>
Street Address <br/>
<input name="streetAddress" type="text"/>
<br/>
Website Address <br/>
<input name="websiteAddress" type="text"/>
<br/>
Email Address </span><br/>
<input name="emailAddress" type="text"/>
</div></td>
<td><div align="center"><span class="style2">City <br/>
<input name="city" type="text"/>
<br/>
State/Region <br/>
<input name="state" type="text"/>
<br/>
Zip Code <br/>
<input name="zipCode" type="text"/>
<br/>
Country <br/>
<input name="country" type="text"/>
<br/>
Phone </span><br/>
<input name="phone" type="text"/>
</div></td>
</tr>
<tr>
<td class="checkboxes" colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><div align="center"></div></td>
</tr>
<tr>
<td class="checkboxes" colspan="2"><div style="height: 7px">
<div style="height: 7px"></div>
<div style="height: 7px"></div>
</div></td>
</tr>
</table>
<h2> </h2>
<h2>Product Information</h2>
<br/>
<br/></td>
</tr>
<tr>
<td><div align="center"><span class="style1">Description </span><br/>
<textarea name="description" cols="0" rows="0">
</textarea>
<br/>
<br/>
</div></td>
</tr>
<tr>
<td height="186"><p align="center"><strong>Attachment: </strong>
<input type="file" name="att" size="26"/>
</p>
<p align="center">
<label>
<input type="submit" name="Send Form" id="Send Form" value="Submit" />
</label>
</p></td>
<td> </td>
<p></p>
<p align="center" class="style2">
<input type="submit" style="width: 100px" value="Send Email"/>
</p>
<p align="center">
<label> <br />
<br />
<br />
</label>
</p>
<p> </p>
</tr>
<tr>
<td class="checkboxes"><br/></td>
</tr>
</table></td>
</tr>
</table>
</form>
<br/>
<br/>
</div></td>
</tr>
<tr>
<td><div align="center"></div></td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<h2 align="center"> </h2>
<h2 align="center"> </h2></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2">
<h2> </h2>
</p>
<p><br/>
</p>
<p></td>
<tr>
<td class="checkboxes" colspan="2">
<br/></td>
</tr>
</form>
<div class="spacer"></div></div>
<p><br/>
</p>
<tr><td colspan="2"> </td>
</tr>
<script type="text/javascript">
document.getElementById('sf').focus();
</script>
</body>
</html>
Here is the PHP CODE:
I am not sure which variables go where, what to duplicate in the PHP, etc
<?php
if($_SERVER['REQUEST_METHOD'] != "POST"){
echo("Unauthorized attempt to access page.</div></div></div></body></html>");
exit;
}
extract($_POST);
if($name == "" || $company == "" || $streetAddress == "" || $websiteAddress == "" || $emailAddress == "" || $city == "" || $state == "" || $zipCode == "" || $country == "" || $phone == ""){
echo "Please go back and fill out all text fields under contact information.</div></div></div></body></html>";
exit;
}
$description = str_replace("\r\n","<br>",$description);
$interior = str_replace("\r\n","<br>",$interior);
$standard = str_replace("\r\n","<br>",$standard);
$enclosure = str_replace("\r\n","<br>",$enclosure);
$fileContent = "<b><u>Contact Information:</u></b><br><br><b>Name:</b> $name<br><br><b>Company:</b> $company<br><br><b>Street Address:</b> $streetAddress<br><br><b>Website Address:</b> $websiteAddress<br><br><b>Email Address:</b> $emailAddress<br><br><b>City:</b> $city<br><br><b>State:</b> $state<br><br><b>Zip Code:</b> $zipCode<br><br><b>Country:</b> $country<br><br><b>Phone:</b> $phone<br><br><b><u>Product Information:</u></b><br><br><b>Description:</b><br> $description<br><br><b>";
$email_from = $emailAddress;
$email_message = $fileContent;
$headers = "From: ".$email_from;
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$att_type};\n" .
" name=\"{$att_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$att_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
//START SPAM PROTECTION
function contains_bad_str($str_to_test) {
$bad_strings = array("content-type:","mime-version:","multipart/mixed","content-transfer-encoding:","bcc:","cc:","to:");
foreach($bad_strings as $bad_string) {
if(eregi($bad_string, strtolower($str_to_test))) {
echo "$bad_string found. Suspected injection attempt - mail not being sent.</div></div></div></body></html>";
exit;
}
}
}
function contains_links($str_to_test) {
$bad_strings = array("http:");
foreach($bad_strings as $bad_string) {
if(eregi($bad_string, strtolower($str_to_test))) {
echo "The phrase 'http:' has been detected. As a method of spam protection, CertifiGroup does not allow this phrase in your email message. If you want to include a link please remove the 'http:' phrase from your link.<br/><br/><a href=\"javascript:history.go(-1)\">Go back to message</a></div></div></div></body></html>";
exit;
}
}
}
function contains_newlines($str_to_test) {
if(preg_match("/(%0A|%0D|\n+|\r+)/i", $str_to_test) != 0) {
echo "newline found in $str_to_test. Suspected injection attempt - mail not being sent.</div></div></div></body></html>";
exit;
}
}
function validZip($str_to_test) {
if(preg_match("/(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)/i", strtolower($str_to_test)) != 0) {
echo $str_to_test . " is not a valid US zip code. As a method of spam prevention we block out zip codes that contain letters. Please go back to the previous page and enter in 11111 or any 5 digit sequence of all numbers. Sorry for the inconvenience.<br/><br/><a href=\"javascript:history.go(-1)\">Go back to message</a></div></div></div></body></html>";
exit;
}
}
contains_bad_str($message);
contains_links($description);
contains_links($interior);
contains_links($standard);
contains_links($enclosure);
contains_newlines($fileContent);
validZip($zipCode);
//END SPAM PROTECTION
mail("somone@something.com", "Information on CE Marking", $email_message, $headers);
$newHeaders = 'MIME-Version: 1.0' . "\r\n";
$newHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$newHeaders .= 'From: Easy CE Marking <info@certifigroup.com>' . "\r\n\r\n";
$autoResponse = "Thank you for contacting Easy CE Marking. One of our sales associates will contact you within 24 hours. We look forward to helping you!";
mail($emailAddress, "Thank you for contacting Easy CE Marking", $autoResponse, $newHeaders);
echo "<span class=\"sectionTitle\">Email Sent Successfully</span><br/><br/>";
echo "Thank you <b>$name</b> for taking the time to contact Easy CE Marking, a response will be sent to <b>$emailAddress</b> as soon as possible.";
?>Many Thanks,
Dilly