I'm guessing that my assembly might be wrong, but it looks fine on receipt whether as html or as text (except in Entourage). I still can't fathom why it won't send all the emails though (or why they're not received).
Here's the code which collates info from the database and prepares it for mailing:
require_once('../../sypphp/sypcms/DbConnector3.php');
$connector = new DbConnector();
$mailinglist = mysql_query('SELECT firstname, email FROM mem_details where allevents = 1 and email <>""') or die(mysql_error());
if (mysql_num_rows($mailinglist) > 0)
{
echo '<b><i>Mail sent to:</i></b><br>';
while ($mail = mysql_fetch_array($mailinglist))
{
$errorlist = array();
$postfrom = $_POST['from'];
$postfrommail = $_POST['frommail'];
$postsubj = $_POST['subject'];
//$postblurb = $_POST['blurb'];
$name = $mail['firstname'];
$to = $mail['email'];
$posthtml = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'
.'<html><head>'
.'<title>SYP Jobs email</title>'
.'<link href="http://www.thesyp.org.uk/scripts/sypmail.css" rel="stylesheet" type="text/css"></head>'
.'<body><p><img src="http://www.thesyp.org.uk/images/mailheader.gif"></p>'
.'<p>Dear '.$name.', </p>'
.$postblurb.
'<p>'.$_POST['body'].'</p><hr>'
.'You are receiving this email because you are signed up to receive the Society of Young Publishers Events Email<b><br />To unsubscribe: </b> Simply log in using your email address and password on <a href="http://www.thesyp.org.uk/members/my_details.php" title="Click here to log in and change your preferences">http://www.thesyp.org.uk/members/my_details.php</a>. Alternatively email <a href="mailto:unsubscribe@thesyp.org.uk">unsubscribe@thesyp.org.uk</a> stating that you wish to unsubscribe from the Events Email'
.'</body></html>';
$posttext = strip_tags($posthtml);
if (trim($_POST['from']) == '') {$errorlist[] = 'You need to enter the sender\'s email address';}
if (trim($_POST['subject']) == '') {$errorlist[] = 'You need to enter a subject';}
if (trim($_POST['body']) == '') {$errorlist[] = 'You need to enter some body';}
if (sizeof($errorlist) !== 0)
{
echo 'The following errors have been encountered:<br>';
foreach ($errorlist as $value)
{
echo $value . '<br>';
}
} //end if errors
else
{
// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
// Grab the FreakMailer class
require_once($_SERVER['DOCUMENT_ROOT'].'/MailClass.inc');
// instantiate the class
$mailer = new FreakMailer();
// Set From name & address
$mailer->FromName = $postfrom;
$mailer->From = $postfrommail;
// Set Reply address
$mailer->AddReplyTo($postfrommail, $postfrom);
// Set the subject
$mailer->Subject = $postsubj;
// Body
//$htmlBody = '<b>My</b><i>HTML</i> Body....';
//$textBody = strip_tags($htmlBody);
$mailer->Body = $posthtml;
$mailer->isHTML(true);
$mailer->AltBody = $posttext;
// Send the mail...
// Add an address to send to.
$mailer->AddAddress($to, $name);
if(!$mailer->Send())
{
echo 'There was a problem sending this mail!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();
echo $name.', '.$to.'<br>';
} //end if no errors
}//end while
echo '<a href="/admin/index.php">Click to return to the index page</a>';
}//end if rows
} //end elseif submitted
Here is the mailer class:
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/phpmailer/class.phpmailer.php');
class FreakMailer extends PHPMailer
{
var $priority = 3;
var $to_name;
var $to_email;
var $From = null;
var $FromName = null;
var $Sender = null;
function FreakMailer()
{
global $site;
// Comes from config.php $site array
if($site['smtp_mode'] == 'enabled')
{
$this->Host = $site['smtp_host'];
$this->Port = $site['smtp_port'];
if($site['smtp_username'] != '')
{
$this->SMTPAuth = true;
$this->Username = $site['smtp_username'];
$this->Password = $site['smtp_password'];
}
$this->Mailer = "smtp";
}
if(!$this->From)
{
$this->From = $site['from_email'];
}
if(!$this->FromName)
{
$this-> FromName = $site['from_name'];
}
if(!$this->Sender)
{
$this->Sender = $site['from_email'];
}
$this->Priority = $this->priority;
}
}
?>
And some other settings
<?php
// Configuration settings for My Site
// Email Settings
$site['from_name'] = 'syp'; // from email name
$site['from_email'] = 'info@mysite.co.uk'; // from email address
// Just in case we need to relay to a different server,
// provide an option to use external mail server.
$site['smtp_mode'] = 'disabled'; // enabled or disabled
$site['smtp_host'] = null;
$site['smtp_port'] = null;
$site['smtp_username'] = null;
?>
I'm also attaching the phpmailerclass and the settings I'm using. Looking at it again, I suspect I'm missing something obvious, but buggered if I can see what it is!