PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've got a fairly straightforward script that sends an email if an error was encountered. The weird thing is, I'm getting 2 emails sent, though I'm pretty sure I'm calling mail() only once.
<?PHP
session_start();
require('config.inc');
require('class.import.php');
require('class.class.php');
require('class.user.php');
$Import = new Import();
#TRUE means load from stored file rather than look for an uploaded file
if(!$Import->loadFile(TRUE))
$message = 'Unable to load classes.txt';
else if(!$Import->commit())
$message = 'Unable to commit data';
$message = 'This is a test message';
if($message)
{
$full_message = <<<MESSAGE
The #### encountered an error while automatically synchronizing itself with ###.
The message was: $message
The error generated was: $Import->error
MESSAGE;
mail('###@###.ca', '###### cron job error',$full_message,"From: ###### ### ###Cron <noreply@####.###.ca>");
echo "error";
}
?>
error only gets output once, but I get 2 emails in my inbox. Any ideas? It's entirely possible it's the system that's misconfigured, but the sysadmin is the kind of guy who, if he was convinced he didn't feel pain, a punch to the face wouldn't change his mind. Needless to say, I want to be darn sure it's not me.
Thanks.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
<?PHP
$full_message = 'test';
mail('###','### cron job error',$full_message,"From: #### Cron <noreply@####.ca>");
mail('###','Test','This is a test body');
?>
Ultimately, these emails will only be sent when something goes horribly wrong, which hopefully should be never, but I would like to figure out what's up.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
I'm taking the simplistic route here...maybe your script is just fine and maybe the problem lies elsewhere i.e. perhaps this script is called multiple times!!
Just a guess - i often find i overlook the simpler possibilities
I could use Swift, but that's an awful lot of work for just a simple "hey, this script is buggered" email.
Removing the echo didn't do anything. I tacked on the microtime() to the end of the message & it appears the emails are being generated up to 2 seconds apart.
I thought it might be called twice or in a funky loop or something. But the output only appears once.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.