Non-Sent email (php)

Hi,

See code.

As is evident, this code sends 6 emails. I know it seems odd, this is a test.

When I run the script on the server (by entering the url), it indicates (via the echos), that it sent all 6 emails.

However, I usually only get 5, once in a while 6.

I thought it was probably doing it too fast; that's why I put in the sleep's.

What can be causing this? Do I need to sleep longer between sends?
<?
function convdate($x) {
	if ($x != "" && substr($x,0,10) != "0000-00-00") {
		$fd = substr($x,5,2) . "/" . substr($x,8,2) . "/" . substr($x,0,4);
	} else {
		$fd = "";
	}		
	return $fd;
}
$today = date('Y') . "-" . date('m') . "-" . date('d');
// test expiration emails
// expiring in future or today
$fsubj = "WHA Membership Expiring";
$fmsg1 = "Thank you for your membership in Women in Health Administration of Southern California (WHA)! We hope you have found your membership rewarding, and we look forward to your participation in WHA in the upcoming year.<br><br>";
$fmsg2 = "This email is to let you know that your membership is expiring ";
$fmsg3 = "We hope you will consider renewing for another year. You can renew your membership online at http://whasocal.org/memb_renewal.php (log in using your email address and password). You can also renew by mailing a check or money order (Payable to: WHA) for ";
$fmsg4 = "to the following address as soon as possible:<br><br>";
$fmsg4 = $fmsg4 . "Women in Health Administration<br>PO Box 77932<br>Corona, CA 92877-0131<br><br>";
$fmsg4 = $fmsg4 . "Please include a copy of this email with your payment, to ensure prompt processing.<br><br>";
$fmsg4 = $fmsg4 . "As you know, WHA membership includes, but is not limited to, the following benefits: networking opportunities, discounted program registration fees, job opportunities, and our Executive Forum newsletter.<br><br>";
$fmsg4 = $fmsg4 . "If you have any questions or comments, please contact us at contact@whasocal.org.<br><br>Thanks again!<br><br>Women in Health Administration of Southern California<br>http://www.whasocal.org";
// expired in past
$psubj = "WHA Membership Expired";
$pmsg1 = "This email is to let you know that your membership in Women in Health Administration of Southern California (WHA) expired on ";
$pmsg2 = "We hope you will consider renewing for another year - you can renew online at http://whasocal.org/memb_renewal.php (log in using your email address and password).  As you know, WHA membership includes, but is not limited to, the following benefits: networking opportunities, discounted program registration fees, job opportunities, and our Executive Forum newsletter.";
$pmsg3 = "We hope you found your membership rewarding, and we look forward to your participation in WHA in the upcoming year, either as a member or a guest at one of our events.";

$pmsg4 = "In case you choose to not renew your membership, as part of our ongoing efforts to identify areas for improvement, we would appreciate if you could spare a few minutes to complete our short exit survey: <a href='http://www.surveymonkey.com/s/CG7NB83'>http://www.surveymonkey.com/s/CG7NB83</a><br><br>";
$pmsg5 = "Thank you in advance for your help. We wish you the best of luck in all of your future endeavors.<br><br>";

$pmsg5 = $pmsg5 . "If you have any questions or comments, please contact us at contact@whasocal.org.<br><br>Women in Health Administration of Southern California<br>http://www.whasocal.org";
$exmsg = "We would appreciate if you could spare a few minutes to complete our short exit survey: http://www.surveymonkey.com/s/CG7NB83<br><br>"; 
$ttdy = mktime(0,0,0, date('m'), date('d'), date('Y'));
$tdp14 = $ttdy + 86400*14;
$gd14 = getdate($tdp14);
$d14 = $gd14['mon'] . "/" . $gd14['mday'] . "/" . $gd14['year'];
$tdp30 = $ttdy + 86400*30;
$gd30 = getdate($tdp30);
$d30 = $gd30['mon'] . "/" . $gd30['mday'] . "/" . $gd30['year'];
// 30 days ago
$tdm30 = $ttdy - 86400*30;
$gdm30 = getdate($tdm30);
$dm30 = $gdm30['mon'] . "/" . $gdm30['mday'] . "/" . $gdm30['year'];
// 60 days ago
$tdm60 = $ttdy - 86400*60;
$gdm60 = getdate($tdm60);
$dm60 = $gdm60['mon'] . "/" . $gdm60['mday'] . "/" . $gdm60['year'];
// 91 days ago
$tdm91 = $ttdy - 86400*91;
$gdm91 = getdate($tdm91);
$dm91 = $gdm91['mon'] . "/" . $gdm91['mday'] . "/" . $gdm91['year'];
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: info@wha.org\r\n";	
//$headers .= 'Bcc: richard@rkassociates.com' . "\r\n";	
//$tostr = "ibsanwal@gmail.com; dnicholson@fulbright.com";	
$tostr = "richard@rkassociates.com";
$subj = $fsubj;
$msg = $fmsg1;
$msg = $msg . $fmsg2 . " in 30 days.<br><br>";
$msg = $msg . "Name: Mary Smith<br>Email: marysmith@aol.com<br>Membership Type: Active<br>Expiration Date: " . $d30 . "<br><br>";
$msg = $msg . $fmsg3 . "$90 " . $fmsg4;
// 30 days out
$res30 = mail($tostr, $subj, $msg, $headers);
echo "30 days sent, res30 = " . $res30 , "<br>";
sleep(2);
$msg = $fmsg1 . $fmsg2 . " in 14 days.<br><br>";
$msg = $msg . "Name: Mary Smith<br>Email: marysmith@aol.com<br>Membership Type: Active<br>Expiration Date: " . $d14 . "<br><br>";
$msg = $msg . $fmsg3 . "$90 " . $fmsg4;
// 14 days out
$res14 = mail($tostr, $subj, $msg, $headers);
echo "14 days sent, res14 = " . $res14 , "<br>";
sleep(2);
$msg = $fmsg1 . $fmsg2 . " today. <br><br>";
$msg = $msg . "Name: Mary Smith<br>Email: marysmith@aol.com<br>Membership Type: Active<br>Expiration Date: " . convdate($today) . "<br><br>";
$msg = $msg . $fmsg3 . "$90 " . $fmsg4;
// Today
$res0 = mail($tostr, $subj, $msg, $headers);
echo "Today sent, res0 = " . $res0 , "<br>";
sleep(2);
$subj = $psubj;
$msg = $pmsg1 . $dm30 . "<br><br>";
$msg = $msg . $pmsg2 . $pmsg3 . $pmsg4 . $pmsg5;
// 30 days ago
$resm30 = mail($tostr, $subj, $msg, $headers);
echo "30 days past sent, resm30 = " . $resm30 , "<br>";
sleep(2);
$msg = $pmsg1 . $dm60 . "<br><br>";
$msg = $msg . $pmsg2 . $pmsg3 . $pmsg4 . $pmsg5;
// 60 days ago
$resm60 = mail($tostr, $subj, $msg, $headers);
echo "60 days past sent, resm60 = " . $resm60 , "<br>";
sleep(2);
$msg = $pmsg1 . $dm91 . "<br><br>";
$msg = $msg . $exmsg . $pmsg5;
// 91 days ago
$resm91 = mail($tostr, $subj, $msg, $headers);
echo "91 days past sent, resm91 = " . $resm91 , "<br>";
exit;
?>

Open in new window

Richard KortsAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
Some of the domain name tools (google that) can show you the MX records. They are part of the DNS.

Have you raised this issue with 1 & 1 yet?  It looks like the script is running the mail() function correctly and if the messages are not getting sent out to the internet for routing to the mail destination, the problem might be on the 1 & 1 side of things.  You might ask them how you can verify that the server sent the information to the internet.  They may not know, but they can surely watch a test case as it happens and tell you whether the message was kept internally at 1 & 1 or released outside of their servers.
0
 
Ray PaseurCommented:
I would think that a second between mail() commands would be more than enough.  Where is this hosted?  Are the MX records OK?
0
 
Richard KortsAuthor Commented:
Ray_Paseur:

It's hosted at 1 & 1.

How do I get at the MX records?

Thanks
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Richard KortsAuthor Commented:
To Ray_Paseur:

See attached image.

Does this shed any light?

Thanks,

Richard
MX-Lookup.jpg
0
 
Ray PaseurCommented:
It looks right, and that tells me that if the messages get out of the 1 & 1 server farm, they would be routed.

When you added the sleep() commands, did the frequency of failures decline?
0
 
Richard KortsAuthor Commented:
Ray,

As a test I tried it from a different server (Chihost). I got all 6.

So it's connected to 1 & 1.

Thanks,

Richard
0
 
Ray PaseurCommented:
Thanks for the points.  I have had good success with ChiHost - both in terms of their record of error-free operation and their tech support.  All the best, ~Ray
0
 
Richard KortsAuthor Commented:
Ray_Paseur:

I'm using Chihost to host 3 or 4 of my customers now, more in the process of moving.

They are VERY good in almost every respect.

Richard
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.