mail()
Moderator: General Moderators
- andyhoneycutt
- Forum Contributor
- Posts: 468
- Joined: Wed Aug 27, 2008 10:02 am
- Location: Idaho Falls
Re: mail()
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
-Andy
Re: mail()
I followed #4 and added in the header and it is still spitting out html code. Any thoughts?
Re: mail()
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()
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!
$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()
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);
{
$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()
Is it not possible to use divs, etc with styles? Thanks.
Re: mail()
You can use that.
Re: mail() sending html from a form
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
$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']
Any ideas as to why?
Thanks
Re: mail()
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?
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()
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.