Jump to content

Multipart Boundary Mail Class


OAFC_Rob

Recommended Posts

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); 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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."--";

Link to comment
Share on other sites

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 by OAFC_Rob
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.