Log in

View Full Version : issue attaching files to mail



weiner769
02-04-2010, 07:16 AM
I am trying to attaching a file to my mail option and it isn't working lol.
Here's my script:

<?php
$to= '_@gmail.com';

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

$subject= 'Application';
$from= 'Website';
$fname = $_REQUEST['fname'] ;
$lname = $_REQUEST['lname'] ;
$phone = $_REQUEST['phone'] ;
$email = $_REQUEST['email'] ;
$state = $_REQUEST['state'] ;
$city = $_REQUEST['city'] ;
$about = $_REQUEST['about'] ;
$experience = $_REQUEST['experience'] ;
$fileatt = $_FILES['file1']['tmp_name'];
$fileatt_type = $_FILES['file1']['type'];
$fileatt_name = $_FILES['file1']['name'];
if (is_uploaded_file($fileatt)) {
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$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}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";

$body= stripslashes ('fname ' . $fname . ' lname ' . $lname . ' phone ' . $phone . ' email ' . $email . ' state ' . $state . ' city ' . $city . ' about ' . $about . ' experience ' . $experience) ;

mail( $to, $subject, $body, $message, $headers, $from );
?><title>sendmail.php</title>

Thank you for submitting your application! We will be contacting you shortly!

I am currently getting: Parse error: syntax error, unexpected $end in /home/p153j78n/public_html/sendmail.php on line 48 (line 48 being the thank you... line)

I don't know if the attach file works either, wasn't able to see if that worked yet. So if you see any issues please inform. Thanks a ton as always!

Schmoopy
02-04-2010, 08:17 AM
There is no second curly brace after the is_uploaded_file if statement:



<?php
$to= '_@gmail.com';

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

$subject= 'Application';
$from= 'Website';
$fname = $_REQUEST['fname'] ;
$lname = $_REQUEST['lname'] ;
$phone = $_REQUEST['phone'] ;
$email = $_REQUEST['email'] ;
$state = $_REQUEST['state'] ;
$city = $_REQUEST['city'] ;
$about = $_REQUEST['about'] ;
$experience = $_REQUEST['experience'] ;
$fileatt = $_FILES['file1']['tmp_name'];
$fileatt_type = $_FILES['file1']['type'];
$fileatt_name = $_FILES['file1']['name'];
if (is_uploaded_file($fileatt)) {
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$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}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";

$body= stripslashes ('fname ' . $fname . ' lname ' . $lname . ' phone ' . $phone . ' email ' . $email . ' state ' . $state . ' city ' . $city . ' about ' . $about . ' experience ' . $experience) ;

mail( $to, $subject, $body, $message, $headers, $from );
} else {
echo "No file uploaded.";
}
?><title>sendmail.php</title>

Thank you for submitting your application! We will be contacting you shortly!