I am trying to use the php mail() function, something I am fairly familiar with, to send an attachment. I've tried to do this using multiple different methods, and each time the mail simply never reaches its destination. Here is the code I currently have: <?php $to = "Eric <myemail@gmail.com>"; $from = "Eric <myemail@gmail.com>"; $subject = "Attach Me NT"; $fileatt = "MyFile.exe"; $fileatttype = "application/exe"; $fileattname = "newname.exe"; $headers = "From: $from"; $file = fopen($fileatt, 'rb' ); $data = fread($file, filesize($fileatt)); $fclose; $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: {$fileatttype};\n" . " name=\"{$fileattname}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileattname}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; if(mail($to, $subject, $message, $headers)) { echo "Done"; } else { echo "Not done."; } ?> PHP: Please help!
I don't mean to sway from your original question, but would it not be easier to get the script to upload it on your server and then mail a link?
It's quite possible the email is getting sent, but the address you are sending it to get is blocking it, most likely due to the .exe file you are trying to attach. Google (and most other programs) will see that as spam and automatically delete it.
What Christian said is very true. All the hosts that I have had to date block all emails containing anything that remotely looks like an executable. Can you convert the file to a zip file and try sending that?