Bug with a php mail's script

Avenueduweb

Verified User
Joined
Jun 8, 2004
Messages
113
Hello,

I've got a problem. I run a script for one of my user with a cron job, and this script send an email. When i run this script directly, the mail is sending and i've got no error in my mainlog (exim), but when this script is running by a cron job, the mail is not sending and in my mainlog, i read that :

2005-03-06 18:30:00 1D7zZo-0003Yc-Ik <= [email protected] U=user P=local S=981 T="test" from <[email protected]> for [email protected]
2005-03-06 18:30:00 1D7zZo-0003Yc-Ik ** [email protected] F=<[email protected]> R=lookuphost T=remote_smtp: SMTP error from remote mailer after MAIL FROM:<[email protected]> SIZE=2036: host mail.mail.com [213.36.240.228]: 553 <[email protected]> unable to verify address
2005-03-06 18:30:00 1D7zZo-0003Yf-Nj <= <> R=1D7zZo-0003Yc-Ik U=mail P=local S=2015 T="Mail delivery failed: returning message to sender" from <> for [email protected]
2005-03-06 18:30:00 1D7zZo-0003Yc-Ik Completed
2005-03-06 18:30:00 1D7zZo-0003Yf-Nj => user <[email protected]> F=<> R=localuser T=local_delivery S=2168
2005-03-06 18:30:00 1D7zZo-0003Yf-Nj Completed
2005-03-06 18:30:00 1D7zZo-0003Yb-IQ <= [email protected] U=user P=local S=1288 T="Cron <user@serveur1> /usr/local/bin/php /home/user/domains/user.net/public_html/sauvegarde-mys" from <[email protected]> for user
2005-03-06 18:30:00 1D7zZo-0003Yb-IQ => user <[email protected]> F=<[email protected]> R=localuser T=local_delivery S=1490
2005-03-06 18:30:00 1D7zZo-0003Yb-IQ Completed

How to run a php mail with a cron job ?

Thanks. Bye.
 
Exactly the same problem. My mail php script works well except if I run it from a cron. The email is not sent from the cron.


Can somebody help us?

Regards.
 
We successfully cron emails every night using our system.

If you want to copy and paste exactly what the path etc in your cron job is maybe that would highlight the problem.

I take it if you access the script via a browser the script runs?

Rob
 
If I run the script from the browser, OK, the email is send

If I run this way the cron:

*/15 * * * * wget http://www.mydomain.com/a_monitor/index.php

OK, the email is send. But then, in the root directory of mydomain.com, they go accumulating index.php, index1.php, index2.php, index3.php etc. In one week my HD will be ful l!!!

If I run this way the cron:

*/15 * * * * /usr/local/bin/php - q - f / home/kserver/domains/mydomain.com/public_html/a_monitor/index.php

Then the email IS NOT send. (but the cron is running, I am sure because I can see it in /var/log/cron)

Looks at a partial report of the mainlog (from /var/log/exim/)

-----------------------------------------------------------------------------
2005-03-11 03:00:00 1D9hs8-0006kN-PZ <= [email protected].16.31 U=kserver P=local S=461 T="Testing" fr
om <[email protected]> for [email protected]
2005-03-11 03:00:03 1D9hs8-0006kN-PZ => [email protected] F=<[email protected]> R=lookuphost T=rem
ote_smtp S=478 H=mail.infomail.tsai.es [195.235.39.34] C="250 Ok, message accepted for delivery"
2005-03-11 03:00:03 1D9hs8-0006kN-PZ Completed
2005-03-11 03:00:36 1D9hs8-0006kP-SU <= [email protected].16.31 U=kserver P=local S=3289 T="Cron <kserver@207> /usr/loca
l/bin/php -q -f /home/kserver/domains/mydomain.com/public_html/a_mon" from <[email protected]> for kserver
2005-03-11 03:00:36 1D9hs8-0006kP-SU remote host address is the local host: 207.XXX.16.31
2005-03-11 03:00:36 1D9hs8-0006kP-SU == [email protected].16.31 R=lookuphost defer (-1): remote host address is the local host
2005-03-11 03:00:36 1D9hs8-0006kP-SU Frozen
2005-03-11 03:15:00 1D9i6e-0006pJ-TD <= [email protected].16.31 U=kserver P=local S=461 T="Testing" fr
om <[email protected]> for [email protected]
2005-03-11 03:15:04 1D9i6e-0006pJ-TD => [email protected] F=<[email protected]> R=lookuphost T=rem
ote_smtp S=478 H=mail.infomail.tsai.es [195.235.39.34] C="250 Ok, message accepted for delivery"
2005-03-11 03:15:04 1D9i6e-0006pJ-TD Completed
2005-03-11 03:15:43 1D9i6f-0006pL-0R <= [email protected].16.31 U=kserver P=local S=3293 T="Cron <kserver@207> /usr/loca
l/bin/php -q -f /home/kserver/domains/mydomain.com/public_html/a_mon" from <[email protected]> for kserver
2005-03-11 03:15:43 1D9i6f-0006pL-0R remote host address is the local host: 207.XXX.16.31
2005-03-11 03:15:43 1D9i6f-0006pL-0R == [email protected].16.31 R=lookuphost defer (-1): remote host address is the local host
2005-03-11 03:15:43 1D9i6f-0006pL-0R Frozen
-------------------------------------------------------------------------------

Thanks for your help !!

Carlos.
 
Do you have a space between the "/" and the word "home"?

No leading space should work.

Jeff
 
The path is fine if there is no space in between / and home.. but I omit the /usr/local/bin/php - q - f from our crons opting to include #!/usr/local/bin/php in the php file itself.

Also have you checked your permissions - they should be 755

Rob
 
The path is correct. No spaces among "/" and "home".
Is very strange, because the cron really works, it is running.

But, I repeat, he doesn't send email if it is run in this form:

/usr/local/bin/php -q -f /home/kserver/domains/mydomain.com/public_html/a_monitor/index.php

I understand that this is a bug in the DA :(
 
Who told you it's a bug in DA?

It doesn't look to me as if it even involves DA.

Jeff
 
Because in a CPanel Server and in an Ensim Server the script work correctly (the cron send email).

Thanks for your reply (my problem is not still resolved)

Carlos.
 
I still don't see how the script even involves DA.

It may not work with DA's install of Exim, but that's not necessarily a bug.

Are you running with the same user name and same user environment?

Jeff
 
My problem is not too resolved. My email script :

PHP:
<?php
$boundary = "-----=".md5(uniqid(rand()));
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
$header .= "\r\n";
$msg = "Ceci est un message au format MIME 1.0 multipart/mixed.\r\n";
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$msg .= "Content-Transfer-Encoding:8bit\r\n";
$msg .= "\r\n";
$date = date("d/m/Y");
$msg .= "Sauvegarde du $date \r\n";
$msg .= "\r\n";
$file = "backup-file.gz";
$fp = fopen($file, "rb");   // b c'est pour les windowsiens
$attachment = fread($fp, filesize($file));
fclose($fp);
$attachment = chunk_split(base64_encode($attachment));
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: application/x-gzip; name=\"$file\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: inline; filename=\"$file\"\r\n";
$msg .= "\r\n";
$msg .= $attachment . "\r\n";
$msg .= "\r\n\r\n";
$msg .= "--$boundary--\r\n";
$destinataire = "[email protected]";
$expediteur   = "[email protected]";
$reponse      = $expediteur;
mail($destinataire, "Sauvegarde de la base de données du $date", $msg,
     "Reply-to: $reponse\r\nFrom: $expediteur\r\n".$header);
?>

And my cron Job :

06 22 * * * /usr/local/bin/php -q -f /home/nolweb/domains/nolweb.net/public_html/sauvegarde-mysql-mail.php

I think there is a bug between my exim and my cron job, because the script run correctly if not started by cron job. Thanks for your help. Bye.
 
Hello,

I've resolved my problem.

Cadena I think you have the same problem.

The solution is :

- Test if your servername.yourdomain.com ping (ping servername.yourdomain.com in ms-dos)
- If the ping not resolved you add in your DNS the domain servername.yourdomain.com but not add in user domain.

See this :

http://help.directadmin.com/item.php?id=16

Thanks. Bye.
 
Hello,

The problem is back, but it's not the same error. If I run my script without cron job, the mail is sending correctly, but if I use cron job to run my script the mail is sending with an attachment empty (0 bytes for the file). What is the solution ? The size of my file is 1.79 MBytes. I have tested to run the script in shell with this on start file :

Code:
#!/usr/local/bin/php -q

But it don't run. Thanks. Bye.
 
Hello,

The problem is resolved. To run the script correctly with cron it's necessary to put the complete path of the file (/home...). Thanks. Bye.
 
Back
Top