Jump to content

Problem sending an email from PHP script


boylesg
 Share

Recommended Posts

The method in the function below, for adding file attachments to an email, works on a windows based web server but not on a linux based web server.It results in the following email contents when the email is sent to my PC. How do you get this to work properly on a linux web server, i.e. such that the file attachment can be opened and saved in Microsoft Outlook etc.Apparently Linus requires a different text boundary than does Windows. Can anyone point me in the direction of a relevant example to follow.function AddInvFileData($FromEmail, &$EmailBody, &$EmailHeader){global $strInvFileName;$fileInv = fopen($strInvFileName, "rb");$nRandNum = 0;$strMIMEBoundary = "";$strMessage = "";$bResult = false;if ($fileInv){$bResult = true;// Read the file contents.$InvFileData = fread($fileInv, filesize($strInvFileName));fclose($fileInv);//Encode it for email - "\r\n" every 76 charcters.$InvFileData = chunk_split(base64_encode($InvFileData));# Get a random 32 bit number using time() as seed.$nRandNum = md5(time());# Define the main headers.$EmailHeader = "From:".$FromEmail."\r\n";$strMIMEBoundary = "==Multipart_Boundary_x{".$nRandNum."}x";$EmailHeader .= "\nMIME-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"{".$strMIMEBoundary."}\"";# Define the message section$strMessage = "This is a multi-part message in MIME format.\n\n" . "--{".$strMIMEBoundary."}\nContent-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n".$EmailBody."\n\n";# Define the attachment section$strMessage .= "--{".$strMIMEBoundary."}\nContent-Type: {TEXT};\n". " name=\"{Invoice}\"\nContent-Disposition: attachment;\n". filename=\"Invoice.txt\"\nContent-Transfer-Encoding: base64\n\n".$InvFileData."\n\n--{".$strMIMEBoundary."}--\n";$EmailBody = $strMessage;}return $bResult;}MIME-Version: 1.0Content-Type: multipart/mixed;boundary="{==Multipart_Boundary_x{2657b10f00b9ee73 7cbb6ee86912cdc0}x}"This is a multi-part message in MIME format.--{==Multipart_Boundary_x{2657b10f00b9ee737cbb6ee869 12cdc0}x}Content-Type: text/plain; charset="iso-8859-1"Content-Transfer-Encoding: 7bitBilling details--------------------Sally WheelerEmail: Phone: Mobile: Delivery details--------------------Email: Phone: Mobile: Paying via: DepositAdditional instructions------------------------Please could I use PayPal?Items------LS014 Olearia lirata Tube $3.50 1 $3.50 SS013 Dillwynia phylicoides Tube $3.50 1 $3.50 SS014 Dillwynia sericea Tube $3.50 1 $3.50 CL003 Glycine clandestina Tube $3.50 1 $3.50 SP001 Brachyscome basaltica Tube $3.50 1 $3.50 Postage: $13.00 ($10.55)-------- Grand Total: $30.50 --{==Multipart_Boundary_x{2657b10f00b9ee737cbb6ee869 12cdc0}x}Content-Type: {TEXT};name="{Invoice}"Content-Disposition: attachment;filename="Invoice.txt"Content-Transfer-Encoding: base64R3JlZydzIEluZGlnZW5vdXMgUGxhbnRzICYgTGFuZHNjYXBlc3 5+fn5JbnZvaWNlfgpBQk46ICA2NSAyODUgMTcwIDI1MX5+fn5+Cn5+fn5EQVRFfjI5LzEvMjAxMQ o1NiBEZXJieSBEcml2ZSx+fn5+SW52b2ljZSN+aW52b2ljZV9udW1iZXIKRXBwaW5nLCBWaWN0b3 JpYSwgMzA3Ni5+fn5+fgpQaG9uZTogOTQwMTM2OTYgICBNb2JpbGU6IDA0MTQzMTg0NzB+fn5+fg pFbWFpbDogZ3JlZ0BncmVnc2luZGlnZW5vdXNsYW5kc2NhcGVzLmNvbS5hdX5+fn5+CldlYjogaH R0cDovL3d3dy5ncmVnc2luZGlnZW5vdXNsYW5kc2NhcGVzLmNvbS5hdX5+fn5+CgpCaWxsaW5nIE RldGFpbHN+fn5+UGF5aW5nIHZpYX4Kfn5+fkRlcG9zaXR+Cn5TYWxseSBXaGVlbGVyfn5+fgp+NT MgRHVuc3RhZmZlbmFnZSBTdEh1cmxzdG9uZSBQYXJrLCBTeWRuZXksIE5TVywgMjE5M35+fn4KRW 1haWw6fnNhbG1AaHVzaG1haWwuY29tfn5+fgpQaG9uZTp+MDIgOTU1ODYyMzJ+fn5+Ck1vYmlsZT p+fn5+fgoKRGVsaXZlcnkgRGV0YWlsc35+fn5+fn4KCn5TYWxseSBXaGVlbGV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1wcm9kdW N0KGQ1MyxnNTMpCn5+fn5+PXByb2R1Y3QoZDU0LGU1NCl+fj1wcm9kdWN0KGQ1NCxnNTQpCn5+fn 5+PXByb2R1Y3QoZDU1LGU1NSl+fj1wcm9kdWN0KGQ1NSxnNTUpCn5+fn5+PXByb2R1Y3QoZDU2LG U1Nil+fj1wcm9kdWN0KGQ1NixnNTYpCn5+fn5TVUJUT1RBTCAgfj1zdW0oZjI3OmY1Nil+fj1zdW 0oaDI3Omg1NikKfn5+fkdTVCAgfkV4Y2x1c2l2ZX5+Cn5+fn5MRVNTIERFUE9TSVQgIH5+fgp+fn 5+VE9UQUwgIH49U1VNKEY1OCxGNTcsLUY1OSl+UFJPRklUfj1TVU0oRjYwLC1INTcsIEY1OSkKCk NoZXF1ZXMsIG1vbmV5IG9yZGVycywgY2FzaCBvciBkaXJlY3QgYmFuayB0cmFuc2ZlcnMgYWNjZX B0ZWQuLi5+fn5+fn5+CihCZW5kaWdvIEJhbmt+IEJTQjogNjMzIDAwMCwgQWNjb3VudCAjOiAxMj cgMjYwIDI3MSkufn5+fn5+fgo=--{==Multipart_Boundary_x{2657b10f00b9ee737cbb6ee869 12cdc0}x}--

Link to comment
Share on other sites

No. The whole Zend framework is a bunch of PHP files that you need to just extract in your hosting space and then include the appropriate ones in your files.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...