OAFC_Rob Posted January 19, 2013 Share Posted January 19, 2013 Hi, I'm having issues with a multipart boundary mail class I've written, I believe the reason it won't send is because the header information is wrong somewhere but I can't seem to spot it. $this->mimeBoundary = "==Multipart_Boundary_x".md5(time())."x"; $this->headers = "MIME-Version: 1.0\r\n"; $this->headers .= "From: ".$from."\r\n"; $this->headers .= "Content-Type: multipart/alternative; boundary=\"".$this->mimeBoundary."\""; $this->body = "This is a multi-part message in MIME format.\r\n"; $this->body .= "--".$this->mimeBoundary."\r\n"; "Content-Type: text/plain; charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit\r\n". $this->textTemplate."\r\n"; $this->body .= "--".$this->mimeBoundary."\r\n". "Content-Type: text/html; charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit\r\n". $this->htmlTemplate."\r\n". "--".$this->mimeBoundary."--\r\n"; return mail($to, $subject, $this->body, $this->headers); Quote Link to comment https://forums.phpfreaks.com/topic/273356-multipart-boundary-mail-class/ Share on other sites More sharing options...
DavidAM Posted January 19, 2013 Share Posted January 19, 2013 Make sure the From: email address is a valid email address owned by the mail server sending the email "Content-Type: text/plain; charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit\r\n". These are basically "headers" to this part of the message. They need to be on separate lines (just as if they were in the mail headers). Also, (I think) there should be a blank line between the last "header" and the content. The message body should look something like this: This is a multi-part message in MIME format. --MIME boundary Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Plain text message here --MIME boundary Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit HTML Message here --MIME boundary-- Check the return value of the mail() function to see if it succeeds or fails. Are you certain the message is not sent? Is it in your spam/junk folder? Quote Link to comment https://forums.phpfreaks.com/topic/273356-multipart-boundary-mail-class/#findComment-1406929 Share on other sites More sharing options...
OAFC_Rob Posted January 26, 2013 Author Share Posted January 26, 2013 Sorry it's taken me ages to actually get back to this issue. I have managed to get the mail class to now send the mail, it seems that my hosting company was blocking the mail for being spam because the email address in the freom section wasn't setup. Now I'm having issues with the multipart boundaries, it is outputting the entire html code etc... $this->mimeBoundary = "Multipart_Boundary_x".md5(time())."x"; $this->headers = "From: ".$this->from."\r\n\r\n"; $this->headers .= "MIME-Version: 1.0\r\n\r\n"; $this->headers .= "Content-Type: multipart/alternative; boundary=".$this->mimeBoundary."\r\n\r\n"; $this->headers .= "Content-Transfer-Encoding: 7bit". "\r\n\r\n"; $this->body = "This is a multi-part message in MIME format.\r\n\r\n"; $this->body .= "--".$this->mimeBoundary."\r\n". "Content-Type: text/plain; charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit\r\n". $this->textTemplate."\r\n"; $this->body .= "--".$this->mimeBoundary."\r\n". "Content-Type: text/html; charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit\r\n". $this->htmlTemplate."\r\n". "--".$this->mimeBoundary."--"; Quote Link to comment https://forums.phpfreaks.com/topic/273356-multipart-boundary-mail-class/#findComment-1408354 Share on other sites More sharing options...
OAFC_Rob Posted January 26, 2013 Author Share Posted January 26, 2013 (edited) fixed it, the code previous had to many \r\n for the headers aftera bit of trail and error on my server. Then it came through as a blank email after further investigation it was because I needed an extra \n for each boundary, bloody hell that was annoying to hunt down! Hope this helps anyone who might have the same problem. $this->mimeBoundary = "Multipart_Boundary_x".md5(time())."x"; $this->headers = "From: ".$this->from."\r\n"; $this->headers .= "MIME-Version: 1.0\r\n"; $this->headers .= "Content-Type: multipart/alternative; boundary=".$this->mimeBoundary."\r\n"; $this->headers .= "Content-Transfer-Encoding: 7bit". "\r\n"; $this->body = "This is a multi-part message in MIME format.\r\n"; $this->body .= "--".$this->mimeBoundary."\r\n". "Content-Type: text/plain; charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit\r\n\n". $this->textTemplate."\r\n"; $this->body .= "--".$this->mimeBoundary."\r\n". "Content-Type: text/html; charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit\r\n\n". $this->htmlTemplate."\r\n". "--".$this->mimeBoundary."--\r\n"; Edited January 26, 2013 by OAFC_Rob Quote Link to comment https://forums.phpfreaks.com/topic/273356-multipart-boundary-mail-class/#findComment-1408357 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.