mailing form with attachment
Posted: Mon Apr 09, 2007 5:09 am
feyd | Please use
this script uploads a file and attaches it to web form to be mailed. please help. thank you
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hello there, could someone please help me. i have been trying to write this very good email attachment script. during online testing it brings a cgi timeout. message goes like this "CGI Timeout. The specified CGI application exceeded the allowed time for processing. The server has deleted the process"
below is my code.Code: Select all
<?php
$name =$_POST["name"];
$email = $_POST["email"];
$age =$_POST["age"];
$access =$_POST["access"];
$sex =$_POST["sex"];
$class =$_POST["class"];
$body ="name: $name<br/>email: $email<br/> age: $age <br> sex: $sex <br/> class: $class";
$to = "tyrohansen@yahoo.com,joesemag@yahoo.co.uk";
$from = "<webmaster@ventug.com>";
$subject = "Here is your attachment";
$fileatt = $HTTP_POST_FILES["userfile"]["tmp_name"];
$fileatttype = $HTTP_POST_FILES["userfile"]["type"];
$fileattname = $HTTP_POST_FILES["userfile"]["name"];
$file = fopen( $fileatt, 'rb' );
$data = fread( $file, filesize( $fileatt ) );
fclose( $file );
$headers = "From: $from";
//encoding
$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/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$body . "\n\n";
$data = chunk_split( base64_encode( $data ) );
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
//sending email
if( mail( $to, $subject, $message, $headers ) ) {
echo "<p>The email was sent.</p>";
}
else {
echo "<p>There was an error sending the file.</p> <br>$fileattname";
}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]