gjiro
27 Oct 2010, 04:45 PM
I have a form which requires the user to upload a resume. But for some reason the email is coming in blank. Can anyone PLEASE help!
Here is the code:
<?
$to="info@businessconsultatsny.com";
$subject="E-mail with attachment";
// get the sender's name and email address
// we'll just plug them a variable to be used later
$from = "Test mail";
// generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
// now we'll build the message headers
$headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\"";
// here, we'll start the message body.
// this is the text that will be displayed
// in the e-mail
$mailbody .="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' /><table width='700' height='250' border='0' cellpadding='0' cellspacing='0' bgcolor='#ffffff' style='margin:6px;'>";
$mailbody=$mailbody."<TR><TD bgcolor='#FFFFFF' colspan='3'><strong>Contact Form Information From BCGNY</strong><br><br></TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Name</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[your_name]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Contact Number</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[contact]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> E-mail</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[email]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Address</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[address]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> City</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[city]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> State</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[state]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Zip Code</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[postal_code]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Position</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[position]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Video Link</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[video_link]."</TD></TR>";
$mailbody=$mailbody."</table></head></html>";
// here, we'll start the message body.
// this is the text that will be displayed
// in the e-mail
$message ="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />";
$message .="<table width='700' height='250' border='0' cellpadding='0' cellspacing='0' bgcolor='#ffffff' style='margin:6px;'>";
$message=$message."<TR><TD bgcolor='#FFFFFF' colspan='3'><strong>Contact Form Information From BCGNY</strong><br><br></TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Name</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[your_name]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Contact Number</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[contact]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> E-mail</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[email]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Address</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[address]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> City</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[city]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> State</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[state]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Zip Code</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[postal_code]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Position</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[position]."</TD></TR>";
$message=$message."</table></head></html>";
// next, we'll build the invisible portion of the message body
// note that we insert two dashes in front of the MIME boundary
// when we use it
$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" . $message . "\n\n";
// now we'll process our uploaded files
foreach($_FILES as $userfile){
// store the file information to variables for easier access
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];
// if the upload succeded, the file will exist
if (file_exists($tmp_name)){
// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){
// open the file for a binary read
$file = fopen($tmp_name,'rb');
// read the file content into a variable
$data = fread($file,filesize($tmp_name));
// close the file
fclose($file);
// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content.
// NOTE: we don't set another boundary to indicate that the end of the
// file has been reached here. we only want one boundary between each file
// we'll add the final one after the loop finishes.
$message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
}
@mail($to, $subject, $message, $headers) or die ("No, the mail did not send!");
header("Location: thankyou.html");
exit;
?>
Here is the .html
<div class="contactform">
<!--contactform starts here -->
<form name="FrmExpress" id="FrmExpress" method="post" enctype="multipart/form-data" action="submit_express.php">
<fieldset>
<div><label>Name *:</label><input name="your_name" id="your_name" type="text"/></div>
<div><label>Contact *:</label><input name="contact" id="contact" type="text"/></div>
<div><label>Email *:</label><input name="email" id="email" type="text"/></div>
<div><label>Address :</label><input name="address" id="address" type="text"/></div>
<div><label>City :</label><input name="city" id="city" type="text"/></div>
<div><label>State :</label><input name="state" id="state" type="text"/></div>
<div><label>Zipcode :</label><input name="postal_code" id="postal_code" type="text"/></div>
<div><label>Position *:</label>
<select name="position" id="position">
<option value="">Select Position</option>
<option value="Graphic-Design-Internship">Graphic Design Internship</option>
<option value="Marketing-Internship">Marketing Internship</option>
<option value="Writing-Internship">Writing Internship</option>
<option value="Sales-Consultant">Sales Consultant</option>
</select>
</div>
<div><label>Video Link :</label><input name="video_link" id="video_link" type="text"/></div>
<div><label>Video Upload :</label><input type="file" name="fileField" id="fileField" value="Choose File" class="text" /></div>
<div><label>Cover Letter :</label><input type="file" name="cover_letter" id="cover_letter" value="Choose File" class="text" /></div>
<div><label>Resume :</label><input type="file" name="resume" id="resume" value="Choose File" class="text" /></div>
<div><label> </label>
<input type="submit" value="Submit" class="buttonsdiv"/>
<input type="reset" value="Reset" class="buttonsdiv"/>
</div>
</fieldset>
</form>
Here is the code:
<?
$to="info@businessconsultatsny.com";
$subject="E-mail with attachment";
// get the sender's name and email address
// we'll just plug them a variable to be used later
$from = "Test mail";
// generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
// now we'll build the message headers
$headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\"";
// here, we'll start the message body.
// this is the text that will be displayed
// in the e-mail
$mailbody .="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' /><table width='700' height='250' border='0' cellpadding='0' cellspacing='0' bgcolor='#ffffff' style='margin:6px;'>";
$mailbody=$mailbody."<TR><TD bgcolor='#FFFFFF' colspan='3'><strong>Contact Form Information From BCGNY</strong><br><br></TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Name</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[your_name]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Contact Number</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[contact]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> E-mail</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[email]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Address</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[address]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> City</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[city]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> State</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[state]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Zip Code</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[postal_code]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Position</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[position]."</TD></TR>";
$mailbody=$mailbody."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Video Link</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[video_link]."</TD></TR>";
$mailbody=$mailbody."</table></head></html>";
// here, we'll start the message body.
// this is the text that will be displayed
// in the e-mail
$message ="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />";
$message .="<table width='700' height='250' border='0' cellpadding='0' cellspacing='0' bgcolor='#ffffff' style='margin:6px;'>";
$message=$message."<TR><TD bgcolor='#FFFFFF' colspan='3'><strong>Contact Form Information From BCGNY</strong><br><br></TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Name</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[your_name]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Contact Number</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[contact]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> E-mail</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[email]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Address</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[address]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> City</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[city]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> State</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[state]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Zip Code</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[postal_code]."</TD></TR>";
$message=$message."<TR><TD width='30%' bgcolor='#FFFFFF' ><strong> Position</strong></TD><TD width='2%' bgcolor='#FFFFFF' ><strong>:</strong></TD><TD width='60%' bgcolor='#FFFFFF'>".$_POST[position]."</TD></TR>";
$message=$message."</table></head></html>";
// next, we'll build the invisible portion of the message body
// note that we insert two dashes in front of the MIME boundary
// when we use it
$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" . $message . "\n\n";
// now we'll process our uploaded files
foreach($_FILES as $userfile){
// store the file information to variables for easier access
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];
// if the upload succeded, the file will exist
if (file_exists($tmp_name)){
// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){
// open the file for a binary read
$file = fopen($tmp_name,'rb');
// read the file content into a variable
$data = fread($file,filesize($tmp_name));
// close the file
fclose($file);
// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content.
// NOTE: we don't set another boundary to indicate that the end of the
// file has been reached here. we only want one boundary between each file
// we'll add the final one after the loop finishes.
$message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
}
@mail($to, $subject, $message, $headers) or die ("No, the mail did not send!");
header("Location: thankyou.html");
exit;
?>
Here is the .html
<div class="contactform">
<!--contactform starts here -->
<form name="FrmExpress" id="FrmExpress" method="post" enctype="multipart/form-data" action="submit_express.php">
<fieldset>
<div><label>Name *:</label><input name="your_name" id="your_name" type="text"/></div>
<div><label>Contact *:</label><input name="contact" id="contact" type="text"/></div>
<div><label>Email *:</label><input name="email" id="email" type="text"/></div>
<div><label>Address :</label><input name="address" id="address" type="text"/></div>
<div><label>City :</label><input name="city" id="city" type="text"/></div>
<div><label>State :</label><input name="state" id="state" type="text"/></div>
<div><label>Zipcode :</label><input name="postal_code" id="postal_code" type="text"/></div>
<div><label>Position *:</label>
<select name="position" id="position">
<option value="">Select Position</option>
<option value="Graphic-Design-Internship">Graphic Design Internship</option>
<option value="Marketing-Internship">Marketing Internship</option>
<option value="Writing-Internship">Writing Internship</option>
<option value="Sales-Consultant">Sales Consultant</option>
</select>
</div>
<div><label>Video Link :</label><input name="video_link" id="video_link" type="text"/></div>
<div><label>Video Upload :</label><input type="file" name="fileField" id="fileField" value="Choose File" class="text" /></div>
<div><label>Cover Letter :</label><input type="file" name="cover_letter" id="cover_letter" value="Choose File" class="text" /></div>
<div><label>Resume :</label><input type="file" name="resume" id="resume" value="Choose File" class="text" /></div>
<div><label> </label>
<input type="submit" value="Submit" class="buttonsdiv"/>
<input type="reset" value="Reset" class="buttonsdiv"/>
</div>
</fieldset>
</form>