简体   繁体   中英

issue in body of the e-mail in php

I am sending mail by php and in the message part, my code is like:

$email_body = "<style type=\"text/css\">
 p {padding:0 !important; margin:0 !important;}
 td {padding:0 10px !important; margin:0 !important; font-family:Verdana, Geneva, sans-serif;}
 td table td {padding:0 !important;}
 </style>
<table align=\"center\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\" style=\"border-collapse:collapse; border:1px solid #565656; font-family:Verdana, Geneva, sans-serif; width:800px;  margin-top:0px; color:#565656;font-weight:normal;font-size:12px; text-align:justify; line-height:1.5em\">
  <tbody>
   <tr>
     <td style=\"border-collapse:collapse; padding-top:10px !important;\">
      message
     </td>
   </tr>
  </tbody>
 </table>";

But in my mail I am getting the full html code whatever it is written for $email_body instead of tabular format. How to do that? Thanks.

You need to set the correct headers:

$to       = 'foo@bar.baz';
$subject  = 'foobar';
$message  = '...'; // the html
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);

Have a look at the manual: http://php.net/manual/en/function.mail.php


You also need a complete html doc, that is:

html
  head
    title
    style
  body
    table

And a tip, if you send html mails, don't use the style tag. I often use this premailer: http://premailer.dialect.ca/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM