0

I have created a script that sends email automatically! My mail message is included in the following variable

$message

But when i include a html code like or something else it is not shown properly in my mail!

2
  • "not shown properly in my mail" is way too vague. We need specifics. Feb 20, 2011 at 7:14
  • You should use well known library for emailing. PHPMailer is very stable and fully featured module. It's open source and also has LITE edition. Feb 20, 2011 at 7:25

2 Answers 2

2

You could do something like:

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$subject = "Subject here";
$message = "email message here";

$sendMail = mail("[email protected]", "$subject", "$message", "$headers" );   
5
  • Unless you have good reason not to, should use UTF-8 rather than iso-8859-1 as the charset. Feb 20, 2011 at 7:24
  • Yeah, if you're doing multilingual, definitely UTF-8.
    – TNC
    Feb 20, 2011 at 7:28
  • no dude i want to include a html code in that $message one! Please help me!
    – user621162
    Feb 20, 2011 at 7:31
  • @divya-mamgai That's the whole point. The HTML will not work unless you set the headers to render the e-mail as HTML, which is what he just detailed.
    – shmeeps
    Feb 20, 2011 at 7:38
  • @divya-mamgai No problem, everyone has to start at some time. Let us know if you need anymore help.
    – shmeeps
    Feb 20, 2011 at 8:00
1

If you are using the mail command make sure you Are setting the right headers eg

    $headers  = "From: $from\r\n";     $headers .= "Content-type: text/html\r\

  mail($to, $subject, $message, $headers);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.