Jump to content

Automatic email response in PHP form


lena_k198

Recommended Posts

Hi all,

I created a form on the web and would like set up an automatic response to be sent to any user who submits the form.

 

The response is generic i.e. the exact same for everyone.

 

The code below is working, I need auto response message. Please help:

            <?php

            if (array_key_exists('button',$_POST)) {

            $post = $_POST;

            $name = $_POST['name'];

            $email = $_POST['email'];

            $comments = $_POST['message'];

           

            $expected = array('name', 'email', 'message');

            $required = array('name', 'email', 'message');

            $missing = array();

 

 

 

           

           

            foreach ($_POST as $key => $value) {

            $temp = is_array($value) ? $value : trim($value);

            if (empty($temp) && in_array($key, $required)) {

            array_push($missing, $key);

            }

            elseif (in_array($key, $expected)) {

            ${$key} = $temp;

            }

            }

           

            if (!empty($email)) {

            $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';

            if (!preg_match($checkEmail, $email)){

              array_push($missing, 'email');

              }

            }

           

            if (empty($missing)){

           

            $to = '[email protected] ';//put your email here

            $subject = $name; // you can put what ever subject you want here

           

            $message = "Name: $name\n\n";

            $message .= "Comments: $comments";

           

            $message = wordwrap($message, 70);

           

            $additionalHeaders = "From: $email";

            if (!empty($email)) {

            $additionalHeaders .= "\r\nReply-To: $email";

            }

           

            $mailSent = mail($to, $subject, $message, $additionalHeaders);

           

            if (empty($missing)){

           

            }

            elseif (empty($missing)){

            $mailSent = true;

            }

           

            if ($mailsent = true){

            unset($missing);

            unset($post);

              }

              } 

 

            }

           

            ?>

           

Link to comment
https://forums.phpfreaks.com/topic/176241-automatic-email-response-in-php-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.