Jump to content
dhanasekar

birthday script with mail functions to customer

Recommended Posts

What do you mean you need a php script? You want us to give you the code? That way you'll keep being new to php for months...i'll guide you and you can write the script on your own. Make a function that will accept one parameter(that will be the email of the user) and will send the email (with your desired content) to the user. Then make another function that will run when you click the button you want. That function should compare the current date with the birthdays in your database. Every time you get a match you can retrieve the user email from the database and call the first function i mentioned. Start writing your code and i'll help you with it. P.S. : I don't know if it's faster/best practice to send the emails while fetching the database or saving them in an array first. Let's hope someone will make it clear.

  • Like 1

Share this post


Link to post
Share on other sites

Hi.. this is wat i tried .<?php//$custdob=date("2001-05-05");$custdob = date("Y/m/d"); //here my date format in my DB is 2010/09/30$link = mysqli_connect('localhost','root','','multinf');if($link && mysqli_select_db('multinf', $link)){ echo $grabBday = "SELECT * FROM custmast WHERE custdob = $custdob";//here it will take the name of the person whose bday is on a particular date if($rs = mysqli_query($link, $grabBday)) { while(mysqli_fetch_array($rs)) { mail('TO_EMAIL', 'HAPPY BIRTHDAY', 'MESSAGE'); } }} ?> after clicking on submit button.. a mail should send to customers mail..pl help.. thanks in advance

Share this post


Link to post
Share on other sites
<?PHP $link = mysqli_connect('localhost', 'root', 'multinf');if ($link && mysql_select_db('multinf', $link)) {        $result = mysql_query("SELECT * FROM custmast WHERE custdob='".date('Y/m/d')."'");        while ($r = mysql_fetch_array($result)) {                mail($r['email'], 'HAPPY BIRTHDAY', 'MESSAGE');        }} ?>

But you shoud make some checker to send only one per day, or script will execute it every time when it loads..

Edited by Haris S

Share this post


Link to post
Share on other sites
$custdob = date("Y/m/d"); //here my date format in my DB is 2010/09/30
extract()You can use extract() to match the only day and month part in database. it will set the year of present timestamp so it will not match with birth year of users in database. You can store the result emails in a array and implode it to string mail() can send email in multiple email id seprating by comma and can call it once to send the emails
while(mysqli_fetch_array($rs)){$sendTo[]=$rs['email'];  }mail(implode(',',$sendTo),'HAPPY BIRTGADAY','YOUR MSG');

http://php.net/mailhttp://php.net/implode and if its suppose to be run once for notification better will be to run it in cron jobs for day interval.

Edited by birbal
  • Like 1

Share this post


Link to post
Share on other sites

I would probably make sense to have a cron script run each day so the script only runs once. have it check for the date, look in the database for all birthdays that fall in this day (the beginning of the day to the end of the day) and then send out an email based on that. The email might as well come from the DB too.

  • Like 1

Share this post


Link to post
Share on other sites
extract()You can use extract() to match the only day and month part in database. it will set the year of present timestamp so it will not match with birth year of users in database. You can store the result emails in a array and implode it to string mail() can send email in multiple email id seprating by comma and can call it once to send the emails
while(mysqli_fetch_array($rs)){$sendTo[]=$rs['email'];  }mail(implode(',',$sendTo),'HAPPY BIRTGADAY','YOUR MSG');

http://php.net/mailhttp://php.net/implode and if its suppose to be run once for notification better will be to run it in cron jobs for day interval.

please write full php code for what you have said friend.. i tried friend , but it doesnt work....

Share this post


Link to post
Share on other sites

why don't you show us what you did, then we can help you with that. Were not in the habit of doing work for people. You should make sure you are doing some basic logging and have errors turned on. Tell us what you are stuck on and what errors you are getting.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...