I am trying to create an html newsletter. I searched the internet, and Mail_Mime, from what I read, is the best and easiest for sending HTML mail. I was able to create a page along with the mailer script, but not all my images are being sent, and none of the text being grabbed from my database is being sent.
Here is my code for the newsletter:
<html>
<body style="margin: 0px; padding: 0px; font-family: Arial, Helvetica, sans-serif">
<table cellpadding="10" cellspacing="0" width="100%" style="background-color: #69C">
<tr>
<td style="text-align: center"><img src="images/nb_logo.png" /></td>
<td style="color: #FFF; text-align: center">
<h1 style="margin: 0px; padding: 0px">Monthly Newsletter</h1>
</td>
<td style="color: #FFF; font-family: Arial, Helvetica, sans-serif; text-align: center">
<h2 style="margin: 0px; padding: 0px">Volume 1, Issue 1</h2>
</td>
</tr>
</table>
<h1 style="width: 80%; margin: auto; padding: 10px 0px; text-align: center; border-bottom: 1px solid #69C">
Latest News from NewsBlog
</h1>
<table style="width: 80%; margin: auto; padding: 0px">
<?php
include('connect.php');
$sql = mysql_query("SELECT * FROM article_info ORDER BY sequence DESC")
or die("Query failed : " . mysql_error());
while($row = mysql_fetch_array($sql)) {
?>
<tr>
<td>
<h1 style="margin: 0px; padding: 10px 0px"><?php echo $row['title']; ?></h1>
<img src="<?php echo $row['photo']; ?>" style="float: left; padding: 2px; margin-right: 10px; border: 1px solid #69C" />
<p style="margin-top: -15px"><?php echo $row['article_info']; ?></p>
</td>
</tr>
<tr>
<td><hr noshade="noshade" style="border-top: 1px solid #FFF; border-right: 1px solid #FFF; border-bottom: 1px solid #69C; border-left: 1px solid #FFF" /></td>
</tr>
<?php } ?>
</table>
<table style="width: 80%; margin: auto; padding: 0px">
<tr>
<td>Unsubscribe...</td>
</tr>
</table>
</body>
</html>
Here is the code for my mailer:
<?php
include "connect.php";
//Using PEAR Mail_Mime
include "Mail.php";
include "Mail/mime.php";
$sql = mysql_query("SELECT * FROM article_info");
$row = mysql_fetch_array($sql);
$mime = new Mail_mime("\r\n");
$mime->setHTMLBody(file_get_contents("mailcontent.php"));
$mime->addHTMLImage("images/nb_logo.png");
$message = $mime->get();
$to = "to.test@email.com";
$hdrs = array(
'From' => "Email Name <from.test@email.com>",
'Subject' => "PEAR Mail_Mime HTML Email Test",
'To' => $to
);
$headers = $mime->headers($hdrs);
$host['host'] = "email-server.satx.rr.com";
$smtp =& Mail::factory('smtp', $host);
$mail = $smtp->send($to, $headers, $message);
if(PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message succcessfully sent!</p>");
}
?>
Any suggestions? Thanks in advance.