Page 1 of 1

mail()

Posted: Wed Sep 03, 2008 12:53 pm
by kippy
If I am trying to send html through mail(), how do I get the message to show up correctly without displaying all of the html code? Thanks.

Re: mail()

Posted: Wed Sep 03, 2008 12:58 pm
by andyhoneycutt
You'll need to supply a content-type with your message. See Example #4 Sending HTML email from php.net's documentation on the mail() function.

-Andy

Re: mail()

Posted: Wed Sep 03, 2008 3:12 pm
by kippy
I followed #4 and added in the header and it is still spitting out html code. Any thoughts?

Re: mail()

Posted: Wed Sep 03, 2008 4:10 pm
by omniuni
I have this working for some of my websites. Can you post your code here so we can take a look at it?

Re: mail()

Posted: Wed Sep 03, 2008 4:24 pm
by kippy
Basically it a simple html page that I have created which includes a a few styles declared in header saved in $msg. the php I am using is:

$to=$_GET['address'];
$subject="subject";
$mailheaders = 'MIME-Version: 1.0' . "\r\n";
$mailheaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mailheaders="From: domain<>\n";
$mailheaders.="Reply-To: email@domain.com\n\n";


mail($to, $subject, $msg, $mailheaders);

I hope this helps!

Re: mail()

Posted: Thu Sep 04, 2008 12:09 am
by starram
function SendMail_MultiPart($HTMLBody,$TEXTBody,$mail_to,$mail_subject,$mail_from)
{
$email_body = "\n--_jkkdsffds32432dlkjifewks_\n";
$email_body .= "Content-type: text/plain\n\n";
$email_body .= $TEXTBody;
$email_body .= "\n--_jkkdsffds32432dlkjifewks_\n";
$email_body .= "Content-type: text/html\n\n";
$email_body .= $HTMLBody;
$email_body .= "\n--_jkkdsffds32432dlkjifewks_--\n";

$content_type = 'Content-Type: multipart/alternative; boundary="_jkkdsffds32432dlkjifewks_";\n charset=iso-8859-1\n';
$headers = "From: ".$mail_from."\r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= $content_type . "\n";
return (mail($mail_to,$mail_subject,$email_body,$headers))?true:false;
}

Use above function.

Call like this
$msg1=str_replace("<br>","\n",$msg;);

SendMail_MultiPart($msg, $msg1, $to, $subject, $mailfrom);

Re: mail()

Posted: Thu Sep 04, 2008 7:56 am
by kippy
Is it not possible to use divs, etc with styles? Thanks.

Re: mail()

Posted: Thu Sep 04, 2008 8:03 am
by starram
You can use that.

Re: mail() sending html from a form

Posted: Fri Sep 05, 2008 2:13 pm
by jmicozzi
In my code when I have the message variable hard coded to the message i.e.
$msg = '<html><body><h1>Hello World</h1></body></html>';

I am able to receive the message in html format, that is the String "Hello World" is bolded etc.

When I read the above string from a textarea on my form ($msg = $_POST['msg'];) I receive the contents (in this case "Hello World") but just in plain text.

Any ideas as to why?

Thanks

Re: mail()

Posted: Sat Sep 06, 2008 11:16 am
by starram
I m sorry but I need to clear something.

Are you entering following text in the text area
<html><body><h1>Hello World</h1></body></html>

?????

If you simply use <h1> tag that will also work.
I used the same thing and it worked perfectly for me.

Try entering only hello world in the textbox
and give other tags hardcoded. If you are not doing so..

Let me know how it goes?

Re: mail()

Posted: Mon Sep 08, 2008 9:08 am
by jmicozzi
The problem is I get different results, if the string is hard coded everything works fine, if I read the same string from a textarea, the visual results are different.