简体   繁体   中英

PHPMailer and Style Sheet formatting

I'm using PHPMailer to automatically send an order acknowledgement as an HTML formatted email. Everything is working as expected except that the formatting of the acknowledgement isn't correct. I included my style sheet with an 'AddAttachment' line which seems to have fixed the header of the acknowledgement form, but the rest of the form still isn't right. Has anyone run into this situation before and know what I need to do to fix it? My edited program code follows in case it'll help!

<?php

require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->SMTPDebug = 0;
$mail->IsSMTP();  // telling the class to use SMTP
$mail->SMTPAuth = true;

$mail->Port       = 25;                  // set the SMTP port
$mail->Host     = "<<smtp server>>"; // SMTP server
$mail->Username = "<<username>>";
$mail->Password = "<<password>>";

$mail->From     = "<<email address>>";
$mail->FromName = "<<name>>";
$mail->AddAddress("<<email address>>");

$mail->Subject  = "Acknowledgement Form";
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->IsHTML(true);

$mail->Body = file_get_contents('<<acknowledgement form page>>');
$mail->AddAttachment('printer.css'); // attach style sheet

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>

You should'nt work with external CSS files in emails... Not many of the email-clients can handle that and not all of your customers use email-clients like Outlook or Thunderbird. Instead, you should disgn you html-code "90s style":-P

eg <p style="width: 200px; text-align: center;">

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