doni49 Posted November 12, 2007 Share Posted November 12, 2007 I'm writing a PHP script that is supposed to send ONE message. However it's sending 80+ messages. For troubleshooting purposes, I boiled it down to the following code: $d = "EMH2 - "; $d .= date("n/j/Y - g:i:s a"); $headers .= "FROM: myemail@mydomain.com\r\n"; mail("myemail@mydomain.com", $d, $d, $headers); What ends up in my inbox is 80+ email messages and the time listed (in the subject) does change so it's not just my mail server going crazy--PHP is actually sending this message that many times Attached is a screen shot of the message list in TBird. Thanks. EDIT: This is being run via a cron job. The cron is supposed to run this every 5 minutes. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
centerwork Posted November 12, 2007 Share Posted November 12, 2007 $d = "EMH2 - "; $d .= date("n/j/Y - g:i:s a"); $headers .= "FROM: myemail@mydomain.com\r\n"; mail("myemail@mydomain.com", $d, $d, $headers); Is this Mail() in a for() loop or while loop? Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2007 Author Share Posted November 12, 2007 No. Here's the ENTIRE CONTENTS of this php file: <?php $d = "EMH2 - "; $d .= date("n/j/Y - g:i:s a"); $headers .= "FROM: myemail@mydomain.com\r\n"; mail("myemail@mydomain.com", $d, $d, $headers); ?> Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 12, 2007 Share Posted November 12, 2007 That's a bit easy to see why... <?php $d = "EMH2 - "; $d .= date("n/j/Y - g:i:s a"); $headers .= "FROM: myemail@mydomain.com\r\n"; mail("myemail@mydomain.com", $d, $d, $headers); ?> Fix the $headers variable, you always concatenate it, and with servers, they are cacheing errors that we are seeing, so just do the following: (remove the concatenating off the $headers) so it looks like this <?php $d = "EMH2 - "; $d .= date("n/j/Y - g:i:s a"); $headers = "FROM: myemail@mydomain.com\r\n"; mail("myemail@mydomain.com", $d, $d, $headers); ?> Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2007 Author Share Posted November 12, 2007 Thanks. But no change. Also if you notice the date line, it creates a new subject/message body for each message. All the messages have different subjects/bodies. And FYI--I just confirmed that it's not the cron damon. I removed the cron job and then I created a php file in my public_html folder that includes this file (the ONLY thing in this new file is to include the other one). My inbox fills up that way too. Also, I've found that it's not just doing 80+ messages and then stopping. It keeps going until I upload a new php file that has the mail line commented out. Shortly after that, the messages stop arriving. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 12, 2007 Share Posted November 12, 2007 what is "EMH2 -" for? Quote Link to comment Share on other sites More sharing options...
centerwork Posted November 12, 2007 Share Posted November 12, 2007 It may be stupid of me, but have you tried using a differant variable for the date() like "$a" or something instead of concatenating. Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2007 Author Share Posted November 12, 2007 what is "EMH2 -" for? EmailHandler version 2 I'm adding it to the subject just to make my life easier--I don't want a bunch of messages arriving with no good way to sort them. Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2007 Author Share Posted November 12, 2007 It may be stupid of me, but have you tried using a differant variable for the date() like "$a" or something instead of concatenating. Not really--and I'm not sure what that would serve. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 12, 2007 Share Posted November 12, 2007 what is "EMH2 -" for? EmailHandler version 2 I'm adding it to the subject just to make my life easier--I don't want a bunch of messages arriving with no good way to sort them. what is "EMH2 -" for? EmailHandler version 2 I'm adding it to the subject just to make my life easier--I don't want a bunch of messages arriving with no good way to sort them. is that a cgi script and if so, could this issue be coming from the cgi script? Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2007 Author Share Posted November 12, 2007 is that a cgi script? No. PHP I don't do CGI. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 12, 2007 Share Posted November 12, 2007 I think there is no condition in your mail code, so every time this file is run then the message is sent. Just my guess though Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 12, 2007 Share Posted November 12, 2007 n~ link=topic=167283.msg737186#msg737186 date=1194846006] I think there is no condition in your mail code, so every time this file is run then the message is sent. Just my guess though which now leads to my follow up question, do you get 80+ emails when the file is only run once? Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2007 Author Share Posted November 12, 2007 n~ link=topic=167283.msg737186#msg737186 date=1194846006] I think there is no condition in your mail code, so every time this file is run then the message is sent. Just my guess though Yes--it's supposed to run EVERY time. But ONLY send ONE message. The trouble is that when the script is run ONCE, I get 80 messages in my inbox. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 12, 2007 Share Posted November 12, 2007 It may be stupid of me, but have you tried using a differant variable for the date() like "$a" or something instead of concatenating. Not really--and I'm not sure what that would serve. you also have the "d" variable defined as two different things. Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2007 Author Share Posted November 12, 2007 n~ link=topic=167283.msg737186#msg737186 date=1194846006] I think there is no condition in your mail code, so every time this file is run then the message is sent. Just my guess though which now leads to my follow up question, do you get 80+ emails when the file is only run once? Yes. See above. Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2007 Author Share Posted November 12, 2007 It may be stupid of me, but have you tried using a differant variable for the date() like "$a" or something instead of concatenating. Not really--and I'm not sure what that would serve. you also have the "d" variable defined as two different things. Yes--Subject and Message body. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 12, 2007 Share Posted November 12, 2007 You can use exit() or die() function after the mail is sent. It will terminate the execution of the script. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 12, 2007 Share Posted November 12, 2007 but you have it defined once as "EMH2 -" and again as date("n/j/Y - g:i:s a"); don't you think this may be causing an error somewhere? Quote Link to comment Share on other sites More sharing options...
centerwork Posted November 12, 2007 Share Posted November 12, 2007 Try this. $body = "EMH2 - "; $d = date("n/j/Y - g:i:s a"); $headers .= "FROM: myemail@mydomain.com\r\n"; mail("myemail@mydomain.com", $body, $d, $headers); I think you are sending your entire email body as a subject line. Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2007 Author Share Posted November 12, 2007 I think you are sending your entire email body as a subject line. Yes I am. I honestly don't care what the message body is. I just want to see a different subject for each message to know that it did in fact create several different messages as opposed to my server sending multiple copies of the same message. As I said in the OP, the posted code is just what I'm using to troubleshoot this issue. The final code won't even send a message. The eventual goal is to have it create a file on the server. What got me started with needing to troubleshoot is that my code was working but then as soon as I tried running it via the cron, it started creating nearly 100 files when it should have created ONE. So I added code that would send me an email listing many of the variables used in the code. I started getting nearly 100 email messages. So I thought maybe there was something wrong with the code and and pulled out everything except the simplest part--sending this email message. I've since deleted the cron job. I created a file in my public_html folder that contains the following code: <?php $d = "EMH2 - "; $d .= date("n/j/Y - g:i:s a"); $headers = "FROM: myemail@mydomain.com\r\n"; mail("myemail@mydomain.com", $d, $d, $headers); print "Date: " .$d . "\n"; ?> I get ONE email message and the date is listed ONCE in my browser. I put that same code in /home/username/EmailHandlers/popmail.php. Then I created a php file in public_html that contains the following code: <?php include "/home/donirela/EmailHandlers/popmail.php"; ?> When I browse to this file, I get 80+ messages and the date is shown ONCE. Quote Link to comment Share on other sites More sharing options...
aschk Posted November 12, 2007 Share Posted November 12, 2007 Something tells me the cron job is wrong... Remove the cron job. Run that PHP script through your browser (once) and await your email (singular). Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2007 Author Share Posted November 12, 2007 Something tells me the cron job is wrong... Remove the cron job. Run that PHP script through your browser (once) and await your email (singular). That's what I did. See my last post. Thanks for taking the time to respond--ALL assistance is greatly appreciated. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 12, 2007 Share Posted November 12, 2007 The subject lines in the screen shot you posted do not match what your script is actually sending. The script would be sending a subject like EMH2 - 11/12/2007 - 9:43:48 am You screen shot shows: EMH2 - 11/12/2007 - 9:43:48:u am Check that you're looking at the correct script. Ken Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2007 Author Share Posted November 12, 2007 I removed the :u from the code after the screen shot was taken. I had it in there expecting to show milliseconds. I'll update the screen shot to reflect this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.