简体   繁体   中英

Sending styled mail with PHP Mailer

I'm trying to send a mail and I want it to be styled. As I know I can't use external file to do that. I'm using inline - style="" - styling. Eventhough I apply correctly it doesn't working. Mail is send but just as a plain text. Here's code that i use to send mail. By the way I'm using PHP-Mailer to send mail

$mail             = new PHPMailer();
$body             = $content;
$mail->IsSMTP();
$mail->Host       = "mail.example.com";
$mail->SMTPAuth   = true; 
$mail->Host       = "mail.example.com"; 
$mail->Port       = 587;
$mail->Username   = "info@example.com";
$mail->Password   = "password";

$mail->SetFrom('info@example.com', 'Name');
$mail->Subject    = $subject;
$mail->Body = $body;

$mail->IsHTML(true);
$mail->AddAddress($person);
$mail->CharSet = 'UTF-8';

Edit(1) : Mail Content

<div style='width: 250px; height: 250px; text-align:center; line-height: 250px>Example</div>

Edit(2) : I used table. Everything seems OK except styling.

If you want support in all email clients (desktop and online) then you should avoid using div. Use tables instead. Also, font-family wont work, because you need to use !important if you want to change the font in gmail (online).

font-family: sans-serif !important;

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