homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

html mail form with attachment is malformed

Msg#: 4631610 posted 9:08 pm on Dec 17, 2013 (gmt 0)

I have a two part mail form that the client now wants the visitor to be able to upload their resume along with the other form data. I found something that worked, but when I went to implement it, the attachment comes through not as a normal attachment file, but encoded gobbledygook


If anything springs to mind, immediately, please let me know. The demo where the code came from works just fine.

form file

<form method="post" action="jobform3.php" enctype="multipart/form-data" name="jobform" onsubmit="return validateForm()">

<b>Please attach your resume:</b>(Please use Word, PDF or Rich Text Format)</b>
<input name="filename" type="file" />

processing file

$tmp_name = $_FILES['filename']['tmp_name'];
$type = $_FILES['filename']['type'];
$file_name = $_FILES['filename']['name'];
$size = $_FILES['filename']['size'];
if (file_exists($tmp_name))

// Check to make sure that it is an uploaded file and not a system file

// Now Open the file for a binary read
$file = fopen($tmp_name,'rb');

// Now read the file content into a variable
$data = fread($file,filesize($tmp_name));

// close the file

// Now we need to encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}(original did not have this closing brace)

$headers = "Reply-To: $name <$email>\r\n";
$headers.= "Return-Path: no-reply <no-reply@$domain>\r\n";
$headers.= "From: no-reply <no-reply@$domain>\r\n";
$headers.= "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; multipart/mixed; charset=iso-8859-1\r\n";
$headers.= "X-Priority: 3\r\n";
$headers.= "X-Mailer: PHP". phpversion() ."\r\n";
$headers.= "Boundary=\"{$mime_boundary}\"";

$message = "This is a multi-part message in MIME format.\n\n";

$message.= "--{$mime_boundary}\n";

$message.= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";

$message.= "Content-Transfer-Encoding: 7bit\n\n";

$message.= "\n\n";
$message.= '<html><body>';
$message.= '<p>Hello, my name is '.$fname.' '.$lname.' and I am interested in a '.$position .' position.</p>';
$message.= '<p>I am seeking '.$time .' work at '.$rate .' an hour.</p>';
$message.= '<p>I am available during the following days:&nbsp;&nbsp;'. $sun .'&nbsp;&nbsp;'. $mon .'&nbsp;&nbsp;'. $tues .'&nbsp;&nbsp;'. $wed .'&nbsp;&nbsp;'. $thurs .'&nbsp;&nbsp;'. $fri .'&nbsp;&nbsp;'. $sat .' </p>';
$message.= '<b>Email:</b> '.$email.'<br/>';
$message.= '<b>Phone:</b> '.$phone.'<br/>';
$message.= '<b>Address:</b> '.$address.', '.$city.', '.$state.' '.$zip.'</p>';
$message.= 'I have lived at this address for '.$howlong.'<br/>';
$message.= '<p><b>Education:</b></p>';
$message.= '<p><b>High School:</b> '. $hsname .'&nbsp;&nbsp;<b>Address:</b> '. $hslocation .'&nbsp;&nbsp;<b>Number of years:</b> '. $hsyears .'&nbsp;&nbsp;<b>Major/Degree:</b> '. $hsdegree .'</p>';
$message.= '<p><b>College:</b> '. $colname. '&nbsp;&nbsp;<b>Address:</b> ' .$collocation .'&nbsp;&nbsp;<b>Number of years:</b>'. $colyears .'&nbsp;&nbsp;<b>Major/Degree:</b> '. $coldegree .'</p>';
$message.= '<p><b>Business/Trade School:</b> '.$trname .'&nbsp;&nbsp;<b>Address:</b> '. $trlocation .'&nbsp;&nbsp;<b>Number of years:</b> '. $tryears .'M<b>ajor/Degree:</b> '. $trdegree .'</p>';
$message.= '<p><b>Professional School:</b> '.$proname .'&nbsp;&nbsp;<b>Address:</b> '. $prolocation .'&nbsp;&nbsp;<b>Number of years:</b> '. $proyears .'&nbsp;&nbsp;<b>Major/Degree:</b> '. $prodegree .'</p><br />';
$message.= '<b>Work History:</b><br/>';
$message.= '<p><b>Company 1:</b>&nbsp;&nbsp; '. $c1name . '&nbsp;&nbsp;<b>Address:</b> ' . $c1address .'<br />&nbsp;&nbsp;<b>Phone:</b> '. $c1phone . '&nbsp;&nbsp;<b>Supervisor:</b> ' .$c1super .'<br />&nbsp;&nbsp;<b>Dates:</b> '. $c1dates . '&nbsp;&nbsp;<b>Pay:</b> ' .$c1pay . '&nbsp;&nbsp;<b>Title:</b> ' .$c1title. '<br />&nbsp;&nbsp;<b>Reason for leaving:</b> ' .$c1leave .'<br/>';
$message.= '<p><b>Company 2:</b>&nbsp;&nbsp; '. $c1name . '&nbsp;&nbsp;<b>Address:</b> ' . $c2address .'<br />&nbsp;&nbsp;<b>Phone:</b> '. $c2phone . '&nbsp;&nbsp;<b>Supervisor:</b> ' .$c2super .'<br />&nbsp;&nbsp;<b>Dates:</b> '. $c2dates . '&nbsp;&nbsp;<b>Pay:</b> ' .$c2pay . '&nbsp;&nbsp;<b>Title:</b> ' .$c2title. '<br />&nbsp;&nbsp<b>Reason for leaving:</b>; ' .$c2leave .'<br/>';
$message.= '<p><b>Company 3:</b>&nbsp;&nbsp; '. $c3name . '&nbsp;&nbsp;<b>Address:</b> ' . $c3address .'<br />&nbsp;&nbsp;<b>Phone:</b> '. $c3phone . '&nbsp;&nbsp;<b>Supervisor:</b> ' .$c3super .'<br />&nbsp;&nbsp;<b>Dates:</b> '. $c3dates . '&nbsp;&nbsp;<b>Pay:</b> ' .$c3pay . '&nbsp;&nbsp;<b>Title:</b> ' .$c3title. '<br />&nbsp;&nbsp; <b>Reason for leaving:</b>' .$c3leave .'<br/>';
$message.= '<b>Can we contact your previous employer?</b> '.$maywe.'<br/>';
$message.= '<b>Can they do the work?</b> '.$cando.'<br/>';
$message.= '<b>Have they been convicted of a crime?</b> '.$crime.'</p>';
$message.= '<p><b>Here is my resume:</b>' .$file_name.'</p>';
$message.= '<p><i>'.$fname.' '.$lname.'</i></p>';
$message.= '</body></html>';

$message.= "--{$mime_boundary}\n";
$message.= "Content-Type: {$type};\n" .
" name=\"{$file_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .

mail($recipient, $subject, $message, $headers) or die("Error!");

Again everything comes through just fine except the attachment. Any assistance would be appreciated.



WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4631610 posted 5:08 pm on Feb 7, 2014 (gmt 0)

Gilead, I notice you were active in another thread here recently and I noticed this oldie laying out here. Did you ever resolve this issue?


Msg#: 4631610 posted 9:09 pm on Feb 7, 2014 (gmt 0)

Finally got it figured out. The problem was with the header.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved