Hi everyone. Am trying to send email reminder for users to update their progress 1 month before end of every quarter. So every February and May etc the email notification will be autosend to the users from the system. Below is the code. Please advise if this is the correct way of doing it or if there is any better way. Thanks a lot.

    <?php 
     $month= $row['MONTH(CURRENT_DATE())'];

    //get email address's
     $con=mysqli_connect("localhost","user","","pq");
    // Check connection
    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $result = mysqli_query($con,"SELECT email FROM tuser"); 

    while($row = mysqli_fetch_array($result))
    {

     if('$month'==2){     
     $to=$row['name']." <".$row['email'].">\r\n";
     $subject="Please find this friendly reminder to update your Operational progress.";
     $headers  = 'MIME-Version: 1.0' . "\r\n";
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     $headers .="To: ".$row['name']." <".$row['email'].">\r\n";
     $headers .= "From: system <system@edu.com>" . "\r\n";
     mail($to, $subject, $email, $headers);
     }
     elseif('$month'==5){     
    $to=$row['name']." <".$row['email'].">\r\n";
     $subject="Please find this friendly reminder to update your Operational progress.";
     $headers  = 'MIME-Version: 1.0' . "\r\n";
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     $headers .="To: ".$row['name']." <".$row['email'].">\r\n";
     $headers .= "From: system <system@edu.com>" . "\r\n";
     mail($to, $subject, $email, $headers);
     }
    } 
    mysqli_close($con); 
     ?> 

Recommended Answers

All 5 Replies

Hi,

small note: in your IF statementes if('$month'==2) (and co.) you are comparing literally the word $month, not his value, against the integer. Single quotes will NOT parse the variable, so in this case you can remove them and write:

if($month == 2)

Or with double quotes:

if("$month" == 2)

Double quotes can parse a variable and expand it to the his value. Read the documentation for more info:

Hi cereal, thanks a lot for your reply. Currently am not sure where to place the above coding. Appreciate if you could advise how to implement autosend for this webpage. Thanks a lot.

I'm referring at the IF/ELSEIF statements at lines 17 and 26.

Thanks cereal, so where to put the above coding for auto reminder email. Should i put it at the login page or how? Thanks.

Should i put it at the login page or how?

It depends, this will send an email only to those clients that are signing in that specific period, if this is your goal then it can work otherwise it would be better to schedule the task, if the latter is the case then check if your hosting control panel allows you to set cron job scripts.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.