Jump to content

Need Help Sending Multi-Part/Alternative Data in PHP Email


phpBeginner06

Recommended Posts

I wrote a php script to send html email and now I would like to be able to send multi-part/alternative to email clients that can not view/display HTML. I tried to change content type to make this work; but I am not sure how I need to add the binarys to my script.

 

<?php

$to="someone@mail.com";
$reply="Reply-To: noresponse@somefakedomain.com";
$from="support@somefakedomain.com";
$subject="About Your Request.....";
$message="<center><div style='border:solid 1px #800000;font-family:arial;font-size:20px;width:400px'><img src='somefakeimage.jpg' width='400px' height='100px'></img><br><br>This is a HTML email.<br><br><br><img src='somefakeimage.jpg' width='400px' height='50px'></div></center>";

@mail($to, $subject, $message, "From: $from\n$reply\nContent-Type: multipart/alternative");

?>

 

Any one know how I can alter my script above to get this to work?

Link to comment
Share on other sites

no - I did not mean binarys - I meant boundries or boundry

 

I want to be able to send both html and text email, for non-html email clients.

 

I do not know how to set boundries so my php email script will send multi-part/alternative as it's content type.

 

Does anyone know how to set the boundries in my script so this will work?

Link to comment
Share on other sites

Add the needed headers and send!
<?php
$headers  = "From: \"Me\"<me@here.com>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
mail('myAddress@hotmail.com', 'Email with attachment from PHP', $message, $headers);
?>

Link to comment
Share on other sites

I tried the code below that "redarrow"; plus added all other needed headers and variables. I am able to send an email to an email address with this code; with all the headers included, but the body of the message does not appear. I have used html in the "$message" variable (email body).

 

So why am I not recieveing a multi-part/alternative email; both in html and/or text? Anyone got any ideas?

 

Here Is My Code

 

<?php
$headers  = "From: \"Business Name Here\"<support@mydomain.com>\n";
$headers .= "Reply-to: \"Business Name Here\"<noresponse@mydomain.com>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
$message = "<div style='color:#00000f'>Hello</div>";
mail('someonesname@aol.com', 'Email Subject Here', $message, $headers);
?>

Link to comment
Share on other sites

I found out how to do what I was trying to do. So if any one else would like to find out how to send a multipart/alternative email in PHP (that sends a HTML Version and also a Text Version, for email clients that do not display HTML); visit this page:

 

http://www.webcheatsheet.com/php/send_email_text_html_attachment.php

 

Thanks redarrow for the help. Could not get your script to work and no one else on this forum (at the time I last replied to this thread) knew how to accomplish this; so I found the answer else were.

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.