Help, Send email once on a page

Started on the old forum in July 2012 · view the original in the archive · old links redirect here

8 replies · 577 views · started 14 years ago · 1 min read

3 participants
Wintch Developer · 68 posts #1

Pls any time i view this page the email will be sending to the user that have birthday 4 the day. I want to send the email 0nce to the user even if the page is viewed many times. Pls help

<?php
$m=date("m");
$d=date("d");
?>
<?php

$chek=$db->select("SELECT * FROM b_users WHERE month='$m' AND day='$d' ORDER BY userid DESC LIMIT 0,10");

 
 if($chek)
  {
   print "<div class='head'><font size='15'>Today is "; 

foreach($chek as $postl)
   {
    if (($d==$postl->day) AND ($m==$postl->month)) echo "<b><a href=\"http://forum.gabbitto.com/profile.php?uid=".$postl->userid."\">".$postl->username."</a></b>, ";
   }
  
print "birthday</font></div>"; 

   $pmail = new PHPMailer();
   $pmail->AddAddress($chek->$email);
   $pmail->From = $config->adminemail;
   $pmail->Subject = "Happy birthday ".$chek->username;
 $pmail->Body = " Happy birthday $chek->username all the memberz of $config->title wishes you an Happy Birthday and a properous years ahead. 
YOU ARE WELC0ME...<br>
".$config->title." Team<br><small>Note: Please Don't reply to this email. If you got this email by mistake then ignore this email.</small>";
   $pmail->IsHTML(true);
   $pmail->Send();
} 
?>
anil14353 Newbie · 8 posts #2

Wintch wrote: Pls any time i view this page the email will be sending to the user that have birthday 4 the day. I want to send the email 0nce to the user even if the page is viewed many times. Pls help

<?php
$m=date("m");
$d=date("d");
?>
<?php

$chek=$db->select("SELECT * FROM b_users WHERE month='$m' AND day='$d' ORDER BY userid DESC LIMIT 0,10");


 
 if($chek)
  {
   print "<div class='head'><font size='15'>Today is "; 

foreach($chek as $postl)
   {
    if (($d==$postl->day) AND ($m==$postl->month)) echo "<b><a href=\"http://forum.gabbitto.com/profile.php?uid=".$postl->userid."\">".$postl->username."</a></b>, ";
   }
  
print "birthday</font></div>"; 

   $pmail = new PHPMailer();
   $pmail->AddAddress($chek->$email);
   $pmail->From = $config->adminemail;
   $pmail->Subject = "Happy birthday ".$chek->username;
 $pmail->Body = " Happy birthday $chek->username all the memberz of $config->title wishes you an Happy Birthday and a properous years ahead. 
YOU ARE WELC0ME...<br>
".$config->title." Team<br><small>Note: Please Don't reply to this email. If you got this email by mistake then ignore this email.</small>";
   $pmail->IsHTML(true);
   $pmail->Send();
} 
?>

instead of running on each page of viewing why don't you try to place code in single file and run a corn job.

Wintch Developer · 68 posts #3

I hav g0ne to my h0sting to check for cron job, and i didnt realy understand it. They said i shud have a knwlodge about linux commands. They just provide a text area 4 me to put my commands, Am lost pls help.

anil14353 Newbie · 8 posts #4

Wintch wrote: I hav g0ne to my h0sting to check for cron job, and i didnt realy understand it. They said i shud have a knwlodge about linux commands. They just provide a text area 4 me to put my commands, Am lost pls help.

The command to run: /usr/local/bin/php -f /home/(username)/public_html/(scriptname).php

Next you'll want to select an option from all the select boxes. Remember to select an option in each box. If you want something to run every day at 4AM, select Minute: 0; Hour: 4; Day: Every; Month: Every; Weekday: Every;

Wintch Developer · 68 posts #5

anil tanx. i used:

0 0 * * * /usr/local/bin/php -q /home/username/public_html/folder/birthdaymail.php

anil14353 Newbie · 8 posts #6

Wintch wrote: anil tanx. i used:

0 0 * * * /usr/local/bin/php -q /home/username/public_html/folder/birthdaymail.php

your welcome Wintch

anil14353 Newbie · 8 posts #7

Peter409 wrote: Pls any time i view this page the email will be sending to the user that have birthday 4 the day.

don't view the page if you want to view the page then write it separately and link it and don't use sending a mail in that. If you write it every time you are viewing mail will be sent. so put the sending a mail code in another file and that file has to be run as a corn job.

eg: birthday.php -> is your viewing page in that don't put mail.

create another file like

alert.php-> in this you have write the retrieving the users and sending a mail to the user who is celebrating b'day.

sorry, for my bad english.

$XTREME$ Developer · 82 posts #8

why are you using corn job for this , you can do it from mysql , create a remadr alert

Wintch Developer · 68 posts #9

xtreme wats the disadvantage of using corn job?

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close