patchwolf wrote in php

Okay, I've googled and gotten nothing. I've read the documentation, and that's not helping. You're my only hope, Obi-wan.

Background
I'm using PHP 5, IIS6, Mdaemon 7.0.1, and verion 1.73 of the PHPMailer class (http://phpmailer.sourceforge.net).

I've used the class before with no problems on Apache -- I don't think that's the problem, as you'll see in just a momemt.

Having worked out how to filter our membership list so I only get the records I want (always useful), the next step is to set up functionality to email those users. I ultimately plan on setting up a cron job to run this at regular intervals.



require_once ('../../../sql_connect.php'); // require the database connection
include_once ('../../../class.phpmailer.php'); // include the mail function

/* Use a swtich statement to select which case runs.  We can use multiple cron jobs to switch between the various cases. */

//if (empty ($_REQUEST['case'])) {
//	$case = 5; // choose an undefined value to force the default case below.
//} else {
	$case = $_REQUEST['case'];
//}

switch ($case) {
	case 0:

		$cutoff = 30; // expired more than this number of days ago
		$notified = 365; // notified this number of days ago
		
		$sql = "SELECT TOP 2 Mem_Number, Title_1, Name_1, Surname_1, Email, Date_Sent_Renewal, EmailList, Renewal_Date FROM BTCMembers WHERE (DATEDIFF(d, Renewal_Date, GETDATE()) > ".$cutoff.") AND (DATEDIFF(d, Date_Sent_Renewal, GETDATE()) > ".$notified.") AND (Email <> '') AND (Date_Sent_Renewal <> '') AND (EmailList = 1) ORDER BY Mem_Number ASC"; 

		$result = odbc_exec($dbc, $sql); // Run the query
		$count = 0; // start a counter
		print ("<table><thead><tr><th>Member Number</th><th>Email</th><th>Renewal Date</th><th>Renewal Sent</th></tr></thead><tbody>");
		while ($temp = odbc_fetch_array($result)) { // fetch the results into an array
			$count++; // increment the counter;
			print ("<tr>
				<td>".$temp['Mem_Number']."</td>
				<td>".$temp['Email']."</td>
				<td>".$temp['Renewal_Date']."</td>
				<td>".$temp['Date_Sent_Renewal']."</td>
			</tr>");
			$mail = new PHPMailer();
				$mail->IsSMTP();							// set mailer to use
				$mail->Host = "mail3.mydomain.com.au";				// specify main and backup server
				$mail->SMTPAuth = false;						// turn SMTP authentication?
				$mail->Username = "web@mydomain.com.au";	// SMTP username
				$mail->From = "web@mydomain.com.au";		// From Address
				$mail->FromName = "Patch";	// From Name
				$mail->isHTML(true);						// Is the email in HTML?
				$mail->Subject = 'Your membership has expired.  Renew now!';	// subject line of the email
				$mail->AddAddress('me@mydomain.com.au'); // testing only.
				$mail->Body = "Test ".$count;
				if(!$mail->Send()) {
					echo "Message could not be sent. <p>";
					echo "Mailer Error: " . $mail->ErrorInfo;
					echo "</p>";
				}
		}
		print ("</tbody></table>");
		print ("<p>There are $count members who have:<ul><li>membership which expired more than $cutoff days ago,</li><li>were sent a renewal notice more than $notified days ago,</li><li>not renewed their membership, and</li><li>agreed to receive communications from us.</li></ul></p>");
		break;


Okay, here's the problem. Mail is sent when $mail->IsMail(); (as opposed to IsSMTP()). That's not a feasible solution, since when mailing a lot of members (we have approx. 160,000), it could cause a server load, and we definitely want visitors to be able to get to the site.

Mail is sent when $mail->IsSMTP(); and $mail->Host = "mail1.mydomain.com.au"; (different host, running same mail server software). Also not feasible, since that host runs our internal mail, and so sending thousands of messages from that would delay delivery of mail internally.

Mail is NOT sent when $mail->IsSMTP(); and $mail->Host = "mail3.mydomain.com.au"; In fact, it doesn't even reach the mail server. The script breaks with the error message "Message could not be sent. Mailer Error: SMTP Error: The following recipients failed: me@mydomain.com.au" This particular message comes from the class.phpmailer.php file. If I change this line from class.smtp.php:

730:        fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);


to this:

730:        fputs($this->smtp_conn,"RCPT TO:\"" . $to . "\"" . $this->CRLF);


then the message is accepted by the mail server, but it appends a " to the end of the email address, causing the domain name to be not found.

Any ideas? Surely this is a challenge someone's willing to tackle.