Jump to content

Supposed to send ONE message. It's sending 80+ messages?


doni49

Recommended Posts

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]

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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  ;D

 

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.

Link to comment
Share on other sites

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  ;D

 

 

which now leads to my follow up question, do you get 80+ emails when the file is only run once?

Yes.  See above.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.