Send automatic email by date in php. PLEASES HELP ME

HI everyone,

This is my first post and I will try to be clear as possible.

I would like to make the code enter the information to be a membership and I also want to make the reminder expired date to renew the membership time. I want to ask them to send auto email to them.

this is the code


$currentDate = date('Y-m-d');

$id = $_POST['student-id'];
$first = $_POST['first-name'];
$last = $_POST['last-name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$date = $_POST['expired'];
if (!empty($id) || !empty($first) || !empty($last) || !empty($email) || !empty($phone) ||
!empty($message) || !empty($date)) {
 $host = "localhost";
    $dbUsername = "root";
    $dbPassword = "";
    $dbname = "student";
    //create connection
    $conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
    if (mysqli_connect_error()) {
     die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
    } else {
     $SELECT = "SELECT email From register Where email = ? Limit 1";
     $INSERT = "INSERT Into register (studentid, firstname, lastname, email, phone, message, expireddate) values(?, ?, ?, ?, ?, ?, ?)";
    $remind_query1 = "SELECT * FROM register WHERE expireddate= '$currentDate'";
     //Prepare statement
     $stmt = $conn->prepare($SELECT);
     $stmt->bind_param("s", $email);
     $rnum = $stmt->num_rows;
     if ($rnum==0) {
      $stmt = $conn->prepare($INSERT);
      $stmt->bind_param("sssssis", $id, $first, $last, $email, $phone, $message, $date);

      //Prepare statement

     if($run1 = $conn->query($remind_query1))
   $rows = $run1->num_rows;
      for ($j = 0; $j < $rows; ++$j)//loop through each user in results and send a reminder email.
        $row = $run1->fetch_array(MYSQLI_NUM);
        $to = $row[3]; //gets the user email address 
          $subject = "Code 30 Reminder";
          $message = "Hi ".$row[1]."\nJust a reminder that your membership date will expiry on the ".$row[6].",\n"
                    ."Please renew your membership\n"."\nThank You"."\nINWASCON";
        $headers = "From: INWASCON";

    echo "New record inserted sucessfully";
     } else {
      echo "Someone already register using this email";

} else {
 echo "All field are required";

To automatically send emails, you have to automatically run a PHP script. You’d use a cronjob/scheduler (part of the OS) for that.

1 Like

how? any example can you show me

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.