I have been taking a crash course trying to learn php/html/javascript/jquery and am probably asking a fairly simple question. I installed phpmailer recently and have been able to send mail with attachments without a problem, but I am trying to make the body of the email HTML. Unfortunately each attempt the formatting is not preserved. I tried copying the same style that I use when I generate the same report to a web page, but it isnt translating to an html email. I have included the code that is relevant. Any glaring oversights?
$htmlBody = '<html><head><title>Calls Yesterday</title></head>';
$htmlBody .='<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
th {
font-weight: bold;
text-align: left;
}
td, th {
padding: 15px 15px 15px 15px;
width: 75px;
vertical-align: top;
text-align: left;
}
.outputData2 {
margin-left: -10px;
margin-right: -10px;
width: 500px;
}
.outputData2 th {
white-space: nowrap;
text-align: left;
padding-right: 10px;
}
.outputData2 td {
white-space: nowrap;
text-align: left;
}
a {
text-decoration: none;
color: #000;
}
strong {
font-weight: bold;
}
</style> <br />';
$htmlBody .= '<div style="width: 640px; height: 500px; margin: 10px 0 0 0; padding: 10px; border: 1px solid #e3e3e3; overflow: auto" ><br />';
$htmlBody .= '<table cellpadding="0" cellspacing="0" align="center" class="outputdata2"><br />';
// $htmlBody .= '<table cellpadding="0" cellspacing="0" th="font-weight: bold; width: 25px; padding: 5px,5px,5px,5px; padding-right: 10px; text-align: left; white-space: nowrap;" td="padding: 5px,5px,5px,5px; width: 25px; text-align: left; vertical-align: top; white-space: nowrap;">';
$htmlBody .= '<th>Campaign</th><th>Number of Calls</th><th>Total Call Duration</th><th>Avg Call Duration</th><th>Call Status</th><br />';
// Setup mail class, recipients and body
$mailer->AddAddress('me@mail.com', 'PHP Novice');
$mailer->Subject = 'Calls on '.$currentDate.'';
$mailer->Body = $htmlBody;
$mailer->IsHTML(true);
$mailer->AltBody = $textBody;
$mailer->AddAttachment($_SERVER['DOCUMENT_ROOT'].'/dashboardOld/campaignFiles/'.$prevClient."_".$currentDate.'.csv', ''.$prevClient."_".$currentDate.'.csv');
$mailer->AddAttachment($_SERVER['DOCUMENT_ROOT'].'/dashboardOld/campaignFiles/'.$prevClient."_".$currentDate.'.json', ''.$prevClient."_".$currentDate.'.json');
$mailer->Send();
$mailer->ClearAddresses();
$mailer->ClearAttachments();
$mailer->IsHTML(false);
I even resorted to include the style sheet in what i passed to phpmailer because the formatting wasn't working when i coded the html settings withing $htmlBody originally.
Any help would be appreciated.
Thanks,
Jeff