scott56hannah Posted December 17, 2007 Share Posted December 17, 2007 I have just created a new PHP mail script to include the ability to send attachments from my website. But the attachements are not sent as files...they are just garbled text....see below the current PHP script and a sample of some of the output that is received... Any help appreciated.. <?php $FirstName = $_POST['FirstName']; #assign value $LastName = $_POST['LastName']; #assign value $Address = $_POST['Address']; #assign value $Country = $_POST['Country']; #assign value $Mobile = $_POST['Mobile']; #assign value $Phone = $_POST['Phone']; #assign value $Email = $_POST['Email']; #assign value $Message = $_POST['Message']; #assign value $to = "sales@test.com"; #recipient $re = "Contact Us Form Feedback from ".$Email; #subject #create the comments that will be sent as text in the message later on $Comments = "First Name :".$FirstName."\n"; $Comments .= "Last Name :".$LastName."\n"; $Comments .= "Address :".$Address."\n"; $Comments .= "Country :".$Country."\n"; $Comments .= "Mobile :".$Mobile."\n"; $Comments .= "Phone :".$Phone."\n"; $Comments .= "Email :".$Email."\n"; $Comments .= "Message :".$Message."\n"; $Attachment = $_FILES['ClientFile']; $FilePath = $_FILES['ClientFile']['tmp_name']; $FileName = $_FILES['ClientFile']['name']; $FileSize = $_FILES['ClientFile']['size']; $FileType = $_FILES['ClientFile']['type']; $FileError = $_FILES['ClientFile']['error']; #open, read, then close the file $fp = fopen( $FilePath, "rb"); $File = fread( $fp, $FileSize); fclose ( $fp ); #create a boundary string $num = md5(time()); $str = "==Multipart_Boundary_x{$num}x"; #encode the data for safe transit $File = chunk_split(base64_encode($File)); #define the header $hdr = "MIME-Version: 1.0\r\n"; $hdr .= "Content-Type: multipart/mixed; "; $hdr .= "boundary=\"($str}\"\r\n"; $hdr .= "From: admin@test.com.au \r\n"; #define message $msg = "This is a multi-part message in MIME format\r\n\n"; $msg .= "--{$str}\r\n"; $msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"; $msg .= "Content-Transfer-Encoding: 8bit\r\n"; $msg .= "$Comments\r\n\n"; $msg .= "--{$str}\r\n"; #define the non-text attachment $msg .= "Content-Type: {$FileType}; "; $msg .= "name=\"{$FileName}\"\r\n"; $msg .= "Content-Disposition: attachment; "; $msg .= "filename=\"{$FileName}\"\r\n"; $msg .= "Content-Transfer-Encoding: base64\r\n"; $msg .= "$File\r\n\n"; $msg .= "--{$str}"; #send mail now that all is prepared $ok = mail($to,$re,$msg,$hdr); if ($ok) { echo "OK"; #Will need to show a Thankyou page } else echo "Not OK"; ?> And now some of the output that is received.... This is a multi-part message in MIME format --==Multipart_Boundary_x357e27b0275d8030798b36f6e54df864x Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit First Name :UserFN Last Name :LastN Address :Addre Country :US Mobile :number Phone :No number Email :user@test.com Message :This message will include a few lines of text This message will include a few lines of text This message --==Multipart_Boundary_x357e27b0275d8030798b36f6e54df864x Content-Type: text/plain; name="Terms of Use.txt" Content-Disposition: attachment; filename="Terms of Use.txt" Content-Transfer-Encoding: base64 VEVSTVMgT0YgVVNFDQoNClRoZSBmb2xsb3dpbmcgbGljZW5zZSBhZ3JlZW1lbnQgcmVndWxhdGVz IGFsbCB1c2Ugb2YgRm9yd2FyZCBTcXVhcmUgU29mdHdhcmUgU29sdXRpb25zIEluYyAoIkZvcndh cmQgU3F1YXJlIikgcHJvZHVjdHMgYW5kIHNlcnZpY2VzLiANCg0KVGhpcyBpcyBhIGxlZ2FsIGFn cmVlbWVudCAoIlRlcm1zIG9mIFVzZSIpIGJldHdlZW4geW91IChlaXRoZXIgYW4gaW5kaXZpZHVh bCBvciBhbiBlbnRpdHkpIGFuZCBGb3J3YXJkIFNxdWFyZS4gWW91IHNob3VsZCByZWFkIHRoZSBm b2xsb3dpbmcgVGVybXMgb2YgVXNlIGNhcmVmdWxseSBiZWZvcmUgdXNpb Quote Link to comment Share on other sites More sharing options...
c_shelswell Posted December 18, 2007 Share Posted December 18, 2007 Have you tried the phpMailer class? It's really good. I use it all the time that may be able to help you. http://phpmailer.codeworxtech.com/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.