简体   繁体   中英

Auto responder mail reverts fill all fields when i have filled them

    <div class="col-md-6">
                                       <div class="contact-form-result"></div>

                                    <!--START form-->
                                    <form name="form" action="post.php" method="post">
                                    <div>
                                        <label>Name :</label> 
                                       <input type="text" id="name" name="name" required>
                                    </div>
                                        <div>
                                        <label>Father's Name :</label> 
                                       <input type="text" id="fname" name="fname" >
                                    </div>
                                        <div>
                                        <label>Age :</label> 
                                       <input type="text" id="age" name="age" required>
                                    </div>
                                        <div>
                                        <label>Sex :</label>
                                         <select name="sex" required>
                                            <option value="">Select</option>
                                            <option value="Male">Male</option>
                                            <option value="Female">Female</option>
                                            <option value="Other">Other</option>
                                        </select>
                                    </div>
                                        <div>
                                        <label>Phone :</label> 
                                       <input type="text" id="phone" name="phone" required>
                                    </div>
                                        <div>
                                        <label>Email :</label> 
                                       <input type="email" id="email" name="email" required>
                                    </div>
                                        <div>
                                        <label>Choose Course :</label> 
                                        <select name="course" required>
                                            <option value="">Select</option>
                                            <option value="Civil Engineering - Comprehensive Course">Civil Engineering - Comprehensive Course </option>
                                            <option value="Civil Engineering - Comprehensive Course">Civil Engineering - Comprehensive Course</option>
                                            <option value="Civil Engineering - Semester Preparatory Course">Civil Engineering - Semester Preparatory Course</option>
                                            <option value="Civil Engineering - Crash Course">Civil Engineering - Crash Course</option>
                                            <option value="Mechanical Engineering">Mechanical Engineering</option>
                                            <option value="Electrical Engineering">Electrical Engineering</option>
                                        </select>
                                    </div>
                                        <div>
                                        <label>Current Semester :</label> 
                                          <select name="semester" required>
                                              <option value="">Select</option>
                                            <option value="Semester 1"> Semester-1 </option>
                                            <option value="Semester-2"> Semester-2</option>
                                            <option value="Semester-3"> Semester-3</option>
                                            <option value="Semester-4"> Semester-4</option>
                                            <option value="Semester-5"> Semester-5</option>
                                            <option value="Semester-6"> Semester-6</option>
                                              <option value="Semester-7"> Semester-7</option>
                                        </select>  


                                        </div>
                                        <div>
                                        <label>Enter Query if Any?</label>
                                        <textarea rows="6" cols="30" name="message"></textarea>
                                        </div>

                                       <!--<div class="col_full hidden">
                                        <input type="text" id="template-contactform-botcheck" name="template-contactform-botcheck" value="" class="sm-form-control" />
                                    </div>-->

                                        <div>
                                            <button value="submit" type="submit" >Submit</button>

                                        </div>

                                    </form>
                                    <!--END form-->
                                    </div>

    <!-- Php Code -->

       <?php

require_once('include/phpmailer/PHPMailerAutoload.php');

$toemails = array();

$toemails[] = array(
    'email' => 'info@engineeringexpress.in, gabrielkoch72@gmail.com', // Your Email Address
    'name' => 'Engineering Express' // Your Name
);

// Form Processing Messages
$message_success = 'We have <strong>successfully</strong> received your Message and will get Back to you as soon as possible.';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($_POST['form'] != '') {

        $name     = isset($_POST['name']) ? $_POST['name'] : '';
        $email    = isset($_POST['email']) ? $_POST['email'] : '';
        $phone    = isset($_POST['phone']) ? $_POST['phone'] : '';
        $fname    = isset($_POST['fname']) ? $_POST['fname'] : '';
        $age      = isset($_POST['age']) ? $_POST['age'] : '';
        $message  = isset($_POST['message']) ? $_POST['message'] : '';
        $sex      = isset($_POST['sex']) ? $_POST['sex'] : '';
        $semester = isset($_POST['semester']) ? $_POST['semester'] : '';
        $course   = isset($_POST['course']) ? $_POST['course'] : '';

        $subject = isset($subject) ? $subject : 'New Message From Contact Form';

        $botcheck = $_POST['template-contactform-botcheck'];

        if ($botcheck == '') {

            $mail->SetFrom($email, $name);
            $mail->AddReplyTo($email, $name);
            foreach ($toemails as $toemail) {
                $mail->AddAddress($toemail['email'], $toemail['name']);
            }
            $mail->Subject = $subject;

            // AutoResponder Settings
            $autoresponder->SetFrom($toemails[0]['email'], $toemails[0]['name']);
            $autoresponder->AddReplyTo($toemails[0]['email'], $toemails[0]['name']);
            $autoresponder->AddAddress($email, $name);
            $autoresponder->Subject = 'We\'ve received your Email';

            $name     = isset($name) ? "Name: $name<br><br>" : '';
            $email    = isset($email) ? "Email: $email<br><br>" : '';
            $phone    = isset($phone) ? "Phone: $phone<br><br>" : '';
            $fname    = isset($fname) ? "Fathers Name: $fname<br><br>" : '';
            $message  = isset($message) ? "Message: $message<br><br>" : '';
            $age      = isset($age) ? "Age : $age <br><br>" : '';
            $sex      = isset($sex) ? "Sex : $sex <br><br>" : '';
            $semester = isset($semester) ? "Semester : $semester <br><br>" : '';
            $course   = isset($course) ? "Course : $course <br><br> " : '';

            $referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : '';

            $body = "$name $email $phone $fname $message $age $sex $semester $course $referrer";

            // AutoResponder Message
            $ar_body = "Thank you for contacting us. We will reply within 24 hours.<br><br>Regards,<br>Engineering Express";

            $mail->MsgHTML($body);
            $autoresponder->MsgHTML($ar_body);
            $sendEmail = $mail->Send();

            if ($sendEmail == true):
                $send_arEmail = $autoresponder->Send();
                echo '{ "alert": "success", "message": "' . $message_success . '" }';
            else:
                echo '{ "alert": "error", "message": "Email <strong>could not</strong> be sent due to some Unexpected Error. Please Try Again later.<br /><br /><strong>Reason:</strong><br />' . $mail->ErrorInfo . '" }';
            endif;
        } else {
            echo '{ "alert": "error", "message": "Bot <strong>Detected</strong>.! Clean yourself Botster.!" }';
        }
    } else {
        echo '{ "alert": "error", "message": "Please <strong>Fill up</strong> all the Fields and Try Again." }';
    }
} else {
    echo '{ "alert": "error", "message": "An <strong>unexpected error</strong> occured. Please Try Again later." }';
}

?>

This wont work...

    if ($_POST['form'] != '') { // you have no inputs named `form`

Suggest adding a hidden input to your form, and checking for that to see if it was submitted...

<input type="hidden" name="POSTED" value="1">
   // then check for submit like this...
if ((isset($_POST['POSTED'])) && ($_POST['POSTED'] ==1)){

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM