Jump to content

Auto send email reminder


benchew0904

Recommended Posts

I'm new to PHP, can anyone can help me with auto sending email?

I have a database which store my customer data which includes their next appointment date etc and I would like to auto send an email reminder to them.

 

I have some problem with the script and I'm not sure it's work.

My email script "To", I'm not sure how should I state the recipient email as there might be a few customers which have the same appointment date.

 

Please do advise on my code.

 

<?php

include 'cogfig.php'; #here store all my connection

$sql = "select email from user where appointment_date <= CURRENT_DATE and appointment_date >= ( CURRENT_DATE - INTERVAL 1 day )";

while (mysql_fetch_array($results)) {

    if ($query) {
        $to = 
        $subject = "Appointment Reminder";
        $message = "Dear Customer \n\n" .
                "We would like to inform you that your appointment is tomorrow. \n" .
                "Your Sincerely\n" .
                "Admin";
        $from = "abc@def.com";
        $headers = "From: $from";
        $sentMail = mail($to, $subject, $message, $headers);

        if ($sentMail) {
            $statusMessage = "Appointment Reminder Successfully Sent. \n";
        } else {
            $statusMessage = "Appointment Reminder Unsuccessfully Sent";
        }
    }
}
?>

Link to comment
Share on other sites

Considering it is a loop, just put the email from the database and it will email everyone with an appointment on that day.

 

Sorry, I'm not strong in programming. What do you mean by "just put the email from the database and it will email everyone with an appointment on that day."?

You mean put at "$To = "?

Link to comment
Share on other sites

First off, your query isn't executing. And I'm unsure if it would run.

 

Secondly, your loop should be

while($row = mysql_fetch_array($results){

 

Your while loop states that for every result, it should do the code within the loop. For example, if there are 3 emails (bob@example, jim@example, me@example), it will do bob@example first, then jim, then me.

 

As it is looping through each result, you should set to:

$to = $row['email'];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.