sniperscope Posted May 25, 2010 Share Posted May 25, 2010 Dear gurus. Last for days i searched whole net (even here), but could not found correct answer. i have a problem what i want to send HTML mail with embed an image (possibly multiple). But my code generates plain text mail. Could you guys give me an idea or correct my mistakes where and what did i wrong? Here is my code: <?php require_once('jcode.php'); $to = "myself@hotmail.com"; $subject = "=?iso-2022-jp?B?".base64_encode(mb_convert_encoding("...Japanese TEXT goes here...","JIS","SHIFT_JIS"))."?="; $sep = sha1(date('r', time())); $header = "Content-Type: multipart/mixed; boundary=\"PHP-mixed-{' .$sep. '}\""; $file = chunk_split(base64_encode(file_get_contents('TEMP_Folder/abcd.gif'))); $header .= "To: You <myself@hotmail.com>\r\n"; $header .= "From: Me <info@example.com>\r\n"; $body = ' --PHP-related-{$sep} Content-Type: multipart/related; boundary="PHP-alt-{' .$sep. '}" --PHP-mixed-{' .$sep. '} Content-Type: multipart/alternative; boundary="PHP-alt-{' .$sep. '}" --PHP-alt-{' .$sep. '} Content-Type: text/plain This is plain text --PHP-alt-{' .$sep. '} Content-Type: text/html <html><head> <title>Test HTML Mail</title> </head> <body> <font color="red">This should be HTML but it doesnt work damn!!!</font> <img src="cid:PHP-CID-{' .$sep. '}" /> </body></html> --PHP-related-{' .$sep. '} Content-Type: image/gif Content-Transfer-Encoding: base64 Content-ID: <PHP-CID-{' .$sep. '}> {' .$file. '}'; mail($to, $subject, $body, $header); ?> Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/ Share on other sites More sharing options...
MadTechie Posted May 25, 2010 Share Posted May 25, 2010 2 quick things, 1. $body as a extra return at the start, remove that, 2. --PHP-related-{$sep} should be --PHP-related-{'.$sep.'} fix them and try again, if it don't work I'll look closer Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062874 Share on other sites More sharing options...
sniperscope Posted May 25, 2010 Author Share Posted May 25, 2010 Dear MadTechie I really appreciate for your interest. Unfortunately, no thing was changed. It is still plain text Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062875 Share on other sites More sharing options...
kenrbnsn Posted May 25, 2010 Share Posted May 25, 2010 This line is incorrect: <?php $header = "Content-Type: multipart/mixed; boundary=\"PHP-mixed-{' .$sep. '}\""; ?> Try <?php $header = 'Content-Type: multipart/mixed; boundary="PHP-mixed-{' . $sep . '}"'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062876 Share on other sites More sharing options...
sniperscope Posted May 25, 2010 Author Share Posted May 25, 2010 kenrbnsn thank you for advise but still same. Got plain text :'( Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062879 Share on other sites More sharing options...
sniperscope Posted May 25, 2010 Author Share Posted May 25, 2010 And this is what i get as mail: From: Me <info@example.com> Return-Path: anonymous@ns.somehost.com X-OriginalArrivalTime: 25 May 2010 05:52:24.0862 (UTC) FILETIME=[733BE3E0:01CAFBCE] --PHP-related-{ce09625e878a0667ce95c0d37cb0cfe8442188d4} Content-Type: multipart/related; boundary="PHP-alt-{ce09625e878a0667ce95c0d37cb0cfe8442188d4}" --PHP-mixed-{ce09625e878a0667ce95c0d37cb0cfe8442188d4} Content-Type: multipart/alternative; boundary="PHP-alt-{ce09625e878a0667ce95c0d37cb0cfe8442188d4}" --PHP-alt-{ce09625e878a0667ce95c0d37cb0cfe8442188d4} Content-Type: text/plain This is plain text --PHP-alt-{ce09625e878a0667ce95c0d37cb0cfe8442188d4} Content-Type: text/html <html><head> <title>Test HTML Mail</title> </head> <body> <font color="red">This should be HTML but it doesnt work damn!!!</font> <img src="cid:PHP-CID-{ce09625e878a0667ce95c0d37cb0cfe8442188d4}" /> </body></html> --PHP-related-{ce09625e878a0667ce95c0d37cb0cfe8442188d4} Content-Type: image/gif Content-Transfer-Encoding: base64 Content-ID: <PHP-CID-{ce09625e878a0667ce95c0d37cb0cfe8442188d4}> {R0lGODlhTgK0AcQAAP////5gAAC8AN4AAOeTkwVPooS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QGWxwJgdQZa+ao7/D5waXSU2iYXIVe4SP8AhXfH2FINrsrBhwFGVALeDMPw57GovrF/WfCWxUObJ AQ+dmATohyMH9NOWE+XQxVhagp8Op59IrCJGLXQCnw7VNzx4oTor+oGILoABLGykcXTUSwZ8VaL1 QSt++FlKHRATLCHVUEivqRrWCMYr7EjSYEAj1dbwtJt5eiQ8AzpPXtHVQjq7WRdj50hI2U8Cs1xg xZ4aMbS9rrCSzRFSJwakimpNdb56233siL7D7sS0McheV8+aAtlZMjQRBSYpf+nZneIPtrQ9ab9u gFqeITSqLlDhQUfKhI3iDoUp6Bd9gCrWXdHHoptoErVmOa312aud/wk8UzpdiFnC/gYCpGzi29Ym 1D/dyG35u6wCr4rLzW5tDy/ } Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062881 Share on other sites More sharing options...
MadTechie Posted May 25, 2010 Share Posted May 25, 2010 try this <?php $to = "tomail@hotmail.com"; $from = "frommail@hotmail.com"; $subject = "=?iso-2022-jp?B?".base64_encode(mb_convert_encoding("...Japanese TEXT goes here...","JIS","SHIFT_JIS"))."?="; // Setting a timezone, mail() uses this. date_default_timezone_set('America/New_York'); // recipients // subject $subject = "Test for Embedded Image & Attachement"; // Create a boundary string. It needs to be unique $sep = sha1(date('r', time())); // Add in our content boundary, and mime type specification: $headers ="Content-Type: multipart/mixed;boundary=\"PHP-mixed-{$sep}\"\r\n"; // additional headers $headers .= "To: You <$to>\r\n"; $headers .= "From: Me <$from>\r\n"; $file = chunk_split(base64_encode(file_get_contents('TEMP_Folder\abcd.gif'))); // Your message here: $body =<<<EOBODY --PHP-mixed-{$sep} Content-Type: multipart/alternative; boundary="PHP-alt-{$sep}" --PHP-alt-{$sep} Content-Type: text/html <html> <head> <title>Test HTML Mail</title> </head> <body> <font color="red">This should be HTML but it doesnt work damn!!!</font> <img src="cid:PHP-CID-{$sep}" /> </body> </html> --PHP-alt-{$sep} Content-Type: text/plain plain text --PHP-alt-{$sep} Content-Type: multipart/related; boundary="PHP-related-{$sep}" --PHP-related-{$sep} Content-Type: image/gif Content-Transfer-Encoding: base64 Content-ID: <PHP-CID-{$sep}> {$file} --PHP-related-{$sep}-- --PHP-alt-{$sep}-- --PHP-mixed-{$sep}-- EOBODY; mail($to, $subject, $body, $headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062883 Share on other sites More sharing options...
sniperscope Posted May 25, 2010 Author Share Posted May 25, 2010 MadTechie Thank you for your time. here is result: Content-Type: multipart/alternative; boundary="PHP-alt-d8f288edd09aa51e82d731247594d0389304687f" --PHP-alt-d8f288edd09aa51e82d731247594d0389304687f Content-Type: text/html <html> <head> <title>Test HTML Mail</title> </head> <body> <font color="red">This should be HTML but it doesnt work damn!!!</font> <img src="cid:PHP-CID-d8f288edd09aa51e82d731247594d0389304687f" /> </body> </html> --PHP-alt-d8f288edd09aa51e82d731247594d0389304687f Content-Type: text/plain plain text --PHP-alt-d8f288edd09aa51e82d731247594d0389304687f Content-Type: multipart/related; boundary="PHP-related-d8f288edd09aa51e82d731247594d0389304687f" --PHP-related-d8f288edd09aa51e82d731247594d0389304687f Content-Type: image/gif Content-Transfer-Encoding: base64 Content-ID: <PHP-CID-d8f288edd09aa51e82d731247594d0389304687f> --PHP-related-d8f288edd09aa51e82d731247594d0389304687f-- --PHP-alt-d8f288edd09aa51e82d731247594d0389304687f-- Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062884 Share on other sites More sharing options...
MadTechie Posted May 25, 2010 Share Posted May 25, 2010 change --PHP-mixed-{$sep} Content-Type: multipart/alternative; boundary="PHP-alt-{$sep}" to --PHP-mixed-{$sep} Content-Type: multipart/alternative;boundary="PHP-alt-{$sep}" EDIT: in fact try the attached [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062885 Share on other sites More sharing options...
sniperscope Posted May 25, 2010 Author Share Posted May 25, 2010 In outlook 2007 got same, but over internet (login to hotmail account) then appear blank mail. Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062886 Share on other sites More sharing options...
MadTechie Posted May 25, 2010 Share Posted May 25, 2010 Tested on outlook 2007 and the attached script works for me! Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062893 Share on other sites More sharing options...
sniperscope Posted May 25, 2010 Author Share Posted May 25, 2010 Tested on outlook 2007 and the attached script works for me! My dear friend, unfortunately, it is plain text on me. this is screenshot What is going wrong i could not find. Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062897 Share on other sites More sharing options...
MadTechie Posted May 25, 2010 Share Posted May 25, 2010 Please use the previously attached file, as it seams to have extra spaces [/img] [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062901 Share on other sites More sharing options...
sniperscope Posted May 25, 2010 Author Share Posted May 25, 2010 do you think, problem is on my mail server? Your screen shots looks excelent Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062903 Share on other sites More sharing options...
MadTechie Posted May 25, 2010 Share Posted May 25, 2010 No, if the email is being sent then it should be okay.. it down to how the client parses the email, Note how you seam to have extra lines, The script I posted was tested on my windows machine, I guess you could try changing the /r/n's to PHP_EOL ie $headers ="Content-Type: multipart/mixed;boundary=\"PHP-mixed-{$sep}\"\r\n"; // additional headers $headers .= "To: You <$to>\r\n"; $headers .= "From: Me <$from>\r\n"; ] to $headers ="Content-Type: multipart/mixed;boundary=\"PHP-mixed-{$sep}\"".PHP_EOL; // additional headers $headers .= "To: You <$to>".PHP_EOL; $headers .= "From: Me <$from>".PHP_EOL; Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062904 Share on other sites More sharing options...
goldjothi Posted May 25, 2010 Share Posted May 25, 2010 I really appreciate for your interest. Unfortunately, no thing was changed. It is still plain text Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062907 Share on other sites More sharing options...
sniperscope Posted May 25, 2010 Author Share Posted May 25, 2010 Same to me... Don't know what else to do. Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062909 Share on other sites More sharing options...
MadTechie Posted May 25, 2010 Share Posted May 25, 2010 I really appreciate for your interest. Unfortunately, no thing was changed. It is still plain text Wow, Strange how within seconds of registering a member would post here and then signs out then the thread starter logs back in to reply! I am not suggesting its the same member or anything (being in the same country doesn't prove anything) Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062914 Share on other sites More sharing options...
sniperscope Posted May 25, 2010 Author Share Posted May 25, 2010 MadTechie he/she is not me :D Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1062924 Share on other sites More sharing options...
sniperscope Posted May 31, 2010 Author Share Posted May 31, 2010 Dear MadTechie Thank you for your advice, my mail is now working. Will you have heart attack if i say i have a tiny problem which is my ISP's mail account works perfect but site's mail address fail and turn into plain text. ie: sniperscope@my-isp.ne.jp <--- OKAY !!! HTML mail sniperscope@hosting.co.jp <-- This mail turn into plain text. same code, same server, same file but turn into plain text just changing mail address. Quote Link to comment https://forums.phpfreaks.com/topic/202801-html-mail-sent-plain-text/#findComment-1065561 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.