Skip to content
PHP Logo

How can PHP be used to automatically generate confirmation emails and follow-up emails after a specific time period?

To automatically generate confirmation emails and follow-up emails after a specific time period using PHP, you can utilize a combination of PHP's mail function and a cron job scheduler. The confirmation email can be sent immediately after a user completes a certain action, while the follow-up email can be scheduled to be sent after a specific time period using a cron job to trigger a PHP script that sends the email.

php
// Code to send confirmation email
$to = "recipient@example.com";
$subject = "Confirmation Email";
$message = "Thank you for your action!";
$headers = "From: sender@example.com";

mail($to, $subject, $message, $headers);

// Code to send follow-up email after a specific time period
$followUpDate = strtotime('+1 week'); // Example: Send follow-up email after 1 week
if (time() >= $followUpDate) {
    $to = "recipient@example.com";
    $subject = "Follow-up Email";
    $message = "Just checking in!";
    $headers = "From: sender@example.com";

    mail($to, $subject, $message, $headers);
}