Forum Moderators: coopster

Message Too Old, No Replies

send out email

         

sqlnew

5:04 pm on Sep 20, 2005 (gmt 0)

10+ Year Member



Hello,
I would like to write a script which sends out emails every Tuesday at 12:00pm. I wrote the following code, but it didn't work. Any suggestions?

<?php
$weekday = date("w");
$hour = date("H");
$minute = date("i");
$second = date("s");
echo $weekday;
echo "<br>", $hour, "<br>";
echo $minute, "<br>";
echo $second, "<br>";
$msg .= "The new paper has been uploaded. ";
$to = "somebody@somewhere.com";
$sub = "The paper for next club meeting.";
$from = "auto_noreply@some.com";

if($weekday ==2 && $hour ==12 && $minute == 00 && $second == 00){
mail($to, $sub, $msg, $from);

}
if(mail()){
echo "The mail works.";
}
else{
echo "something wrong.";
}
?>

Thanks in advance.

henry0

6:02 pm on Sep 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SQLnew, Welcome to WebMasterWorld

Could you write a script that deals only with the email part and not worrying about the date/time?

Then do a cron job

If you cannot directly set it up
Your ISP will do the cron part

sqlnew

6:19 pm on Sep 20, 2005 (gmt 0)

10+ Year Member



Thank you very much for your kind reply. I have tried the code without the date/time part, but still it didn't work. I don't think I can set up the cron job. If I ask my ISP to work on this, can you tell me what I should tell him/her? Can I just tell him that my mail() function does not work? Can you tell me which part should the ISP set up?
Thanks again.

henry0

6:39 pm on Sep 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I will first del all timing sections from my email send it to myself and verify that it does the work.

When done (I assume that your site runs on a *nix server)

Call your ISP and simply state that you have a cron job to run and that you have made the script that should be timely executed

Come with a schedule and that's it

Writing the cron is not a lengthy task and if they charge you it should be very affordable :)

henry0

6:44 pm on Sep 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



BTW
Here is a Cron table tutorial [phpfreaks.com]
I do not think but I can be wrong that we have one in our "Library"

sqlnew

7:17 pm on Sep 20, 2005 (gmt 0)

10+ Year Member



Thanks again.
I have tried the mail function again without any date/time, but still it didn't work. The following is my code.

<?php
$msg .= "The new paper has been uploaded. ";
$to = "sqlnew@someuni.edu";
$sub = "The paper for next club meeting.";
$from = "auto_noreply@some.com";
mail($to, $sub, $msg, $from);
if(mail()){
echo "Good.";
}
else{
echo "No.";
}
?>

Can you tell me whether the ISP need set up something before the mail() function run?

henry0

7:50 pm on Sep 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try this
<?
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$to="sqlnew@someuni.edu";

$sub = "The paper for next club meeting.";
$from = "auto_noreply@some.com";

$message="The new paper has been uploaded. ";

if (@mail($to, $sub, $from, $message, $headers)) {
echo('<h3><b>Thank you, etc.</h3>');

} else
{
echo('<p>Hmmm! Slight email problem...<br>
aaaaaaaaaaaaaaaa</p>');
}

?>

Your ISP needs location of your mail script

sqlnew

8:11 pm on Sep 20, 2005 (gmt 0)

10+ Year Member



I tried your code and still could not send out the email( the else{ } block run). Do you think the ISP need change something?

henry0

8:40 pm on Sep 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK just a problem that accoured while I typed the previous code snippet to fit your needs
that one works as is (I tested it)
change it at your will

also only the OK part of the message from the previous script had an error but the mail workedd ;
I received the emails
<?
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$to="aaaa@.com";

$subject="Save those links";

$message='Henry: New demo activated check Dir: '.$rand ;

if (@mail($to, $subject, $message, $headers)) {
echo('<h3><b>Thank you, #*$!xi.com is notified, we will help you as needed.</h3>');

} else
{
echo('<p>Hmmm! Slight email problem...<br>
Please email to site admin from our contact form (Location: Home Page) and explain what occured, thank you.</p>');
}
?>
<Edit>
OOPPSS: Read occurred not accoured :)
</edit>

sqlnew

9:11 pm on Sep 20, 2005 (gmt 0)

10+ Year Member



Thank you very much for your time, but I still could not send out the email(still the else{ } block run). Why this happens it works for you, not for me?( Pardon me. I am new to this field.) Is this because there is something need set up on my server side? I really appreciate your help.

henry0

9:26 pm on Sep 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sqlnew I am puzzled
It works not even on my test bed but I loaded it on my production server and it runs fine (getting mail and OK message)

Did you try it as is; just changing the email address?

regardless of the error do you get any mail?

If it does not work I hope that the cavalry will show up for I am clueless
Sorry

henry0

9:29 pm on Sep 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I left a $rand in the script
but it does not hurt (although not needed)
My production server had no problem with it

sqlnew

9:41 pm on Sep 20, 2005 (gmt 0)

10+ Year Member



Thanks again. I know you were spending so much time trying to help me out. I am not so lucky to get it run on my server, no matter I delete the $rand or leave it there. Yes, I copied the original code and only changed the email address with my own. I didn't receive the email. I am still wondering if my ISP need set up something before the mail() function can actually run. Do you think so?
Many thanks.

sqlnew

2:59 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



Hello, Henry0,
I contacted my ISP and he said that we cannot use the native "mail()" function because that relies on an MTA (mail transfer agent) such as sendmail being installed on the system the webserver is being installed
on. We have no use for running sendmail on this system since it's not a mailserver.
Thanks for your time.

dmmh

3:08 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



its always the most obvious one forgets, in this case sendmail :)
glad you figured it out though

elgumbo

3:09 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



Time to move hosts perhaps?