PHP Auto Responder

two white message balloons

PHP Auto Responder is a script that automatically sends a response to an email or form submission. This can be used for a variety of purposes, such as confirming receipt of an email or form submission, sending a thank-you message, or sending a confirmation link.

Here’s an example of a simple PHP script that can be used as an auto-responder:

Copy code<?php
    // Recipient email address
    $to = '[email protected]';

    // Subject of the auto-response email
    $subject = 'Auto-Response';

    // Message to be sent in the auto-response email
    $message = 'Thank you for contacting us. We will get back to you as soon as possible.';

    // Additional headers
    $headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    // Send the email
    mail($to, $subject, $message, $headers);

    echo 'Auto-response sent.';
?>

This script uses the built-in mail() function in PHP to send an email to the recipient specified in the $to variable. The email has the subject specified in the $subject variable, and the message body specified in the $message variable. The $headers variable is used to set the “From” and “Reply-To” headers, as well as the “X-Mailer” header, which is used to identify the software used to send the email.

You can use this script as is and can put it in a handler script which can handle the form submission or email sending and this script will run automatically on submission/receiving email.

You can also customize this script to include more information from the form submission or email, such as the sender’s name or message. For example, you can use the $_POST or $_GET arrays to access the data from a form submission and include it in the message.

It’s also a good practice to validate the data before sending the auto-response, and use appropriate error handling in case of any errors.

Additionally, you may want to consider using a library or a framework to handle email sending, such as PHPMailer, it will give you more flexibility and features like attachments,html emails and logging in your script.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.