PDA

View Full Version : Bug with a php mail's script



Avenueduweb
03-06-2005, 09:44 AM
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 <= user@serveur1.avenueduweb.net U=user P=local S=981 T="test" from <user@serveur1.avenueduweb.net> for mail@mail.com
2005-03-06 18:30:00 1D7zZo-0003Yc-Ik ** mail@mail.com F=<user@serveur1.avenueduweb.net> R=lookuphost T=remote_smtp: SMTP error from remote mailer after MAIL FROM:<user@serveur1.avenueduweb.net> SIZE=2036: host mail.mail.com [213.36.240.228]: 553 <user@serveur1.avenueduweb.net> 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 user@serveur1.avenueduweb.net
2005-03-06 18:30:00 1D7zZo-0003Yc-Ik Completed
2005-03-06 18:30:00 1D7zZo-0003Yf-Nj => user <user@serveur1.avenueduweb.net> 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 <= user@serveur1.avenueduweb.net U=user P=local S=1288 T="Cron <user@serveur1> /usr/local/bin/php /home/user/domains/user.net/public_html/sauvegarde-mys" from <user@serveur1.avenueduweb.net> for user
2005-03-06 18:30:00 1D7zZo-0003Yb-IQ => user <user@serveur1.avenueduweb.net> F=<user@serveur1.avenueduweb.net> 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.

cadena
03-11-2005, 02:43 AM
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.

matrixx
03-11-2005, 02:53 AM
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

cadena
03-11-2005, 03:29 AM
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 <= kserver@207.XXX.16.31 U=kserver P=local S=461 T="Testing" fr
om <kserver@207.XXX.16.31> for recipient@domain.com
2005-03-11 03:00:03 1D9hs8-0006kN-PZ => recipient@domain.com F=<kserver@207.XXX.16.31> 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 <= kserver@207.XXX.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 <kserver@207.XXX.16.31> 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 == kserver@207.XXX.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 <= kserver@207.XXX.16.31 U=kserver P=local S=461 T="Testing" fr
om <kserver@207.XXX.16.31> for recipient@domain.com
2005-03-11 03:15:04 1D9i6e-0006pJ-TD => recipient@domain.com F=<kserver@207.XXX.16.31> 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 <= kserver@207.XXX.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 <kserver@207.XXX.16.31> 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 == kserver@207.XXX.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.

nobaloney
03-11-2005, 07:02 AM
Do you have a space between the "/" and the word "home"?

No leading space should work.

Jeff

matrixx
03-11-2005, 11:10 AM
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

cadena
03-11-2005, 12:10 PM
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 :(

nobaloney
03-14-2005, 07:31 PM
Who told you it's a bug in DA?

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

Jeff

cadena
03-15-2005, 12:34 PM
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.

nobaloney
03-15-2005, 07:07 PM
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

Avenueduweb
03-16-2005, 04:03 AM
My problem is not too resolved. My email script :



<?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 = "test@test.com";
$expediteur = "mail@mail.com";
$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.

Avenueduweb
03-28-2005, 08:55 AM
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.

Avenueduweb
09-13-2005, 09:03 AM
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 :


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

But it don't run. Thanks. Bye.

Avenueduweb
09-14-2005, 06:12 AM
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.