7

I have an enquiry form where once the user click the submit button the form mailhandler.php and sends the email to myself.
I have tried doing this through php but its not fully working as I do not recieve any emails.

Here is my mail handler.php

<?php
if(isset($_POST['buttonSubmit'])){
    $to = "xxxxxxx"; // my email has been hidden
    $from = $_POST['emailInput']; // this is the sender's Email address
    $first_name = $_POST['fNameInput'];
    $last_name = $_POST['lNameInput'];
    $subject = "Form submission";
    $subject2 = "Copy of your form submission";
    $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['requestField'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['requestField'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>

and my form

<form class = "form" name = "productEnquiry" id = "myForm" onsubmit="return validateForm();" action ="mailhandler.php" method = "post">

    <div class = "FormImage">
        <img src="images/productenquiry.html/enquiry2.jpg" id = "productEnquiryImage">
    </div>

    <div class = "form-element">
        <label>Select category:</label>
        <select id = "ddl1" onclick="valDDL1();" class = "input" onchange = "configDDL(this);">
            <option value = "Default">Select product category</option>
            <option value = "Salts">Salts</option>
            <option value = "Fruits">Fruits</option>
            <option value = "Cereals">Cereals</option>
            <option value = "Meats">Meats</option>
            <option value = "Drinks">Drinks</option>
            <option value = "Other">Other</option>
        </select><span class = 'error' id = "errorDDL1">*</span>
    </div>

    <br>

    <div class = "form-element">
        <label>Select product:</label>
        <select id = "ddl2" onclick="valDDL2();" class = "input"  class = "ddl">
            <option></option>
        </select><span class = 'error' id = "errorDDL2">*</span>
    </div>
    <br>

    <div class = "form-element">
        <label>First Name:</label>
        <input type = "text" class = "input" name = "fNameInput" placeholder="John" onkeyup="valFirstName();" onchange="valFirstName();" id = "strFirstName"><span class='error' id="errorFirstName">*</span>
    </div>
    <br>

    <div class = "form-element">
        <label>Last Name:</label>
        <input type = "text" class = "input" name = "lNameInput" placeholder = "Doe" onkeyup = "valLastName();" onchange = "valLastName();" id = "strLastName"><span class='error' id="errorLastName">*</span>
    </div>
    <br>

    <div class = "form-element">
        <label>Contact Phone Number:</label>
        <input type = "text" class = "input" name = "phoneInput" placeholder = "123456789" onkeyup="valPhone();" onchange="valPhone();" id = "strPhone"><span class='error' id="errorPhone">*</span>
    </div>
    <br>

    <div class = "form-element">
        <label>Contact Email:</label>
        <input type = "text" class = "input" name = "emailInput" placeholder = "example@example.com" onkeyup = "valEmail();" onchange = "valEmail();" id = "strContactEmail"><span class='error' id="errorContactEmail">*</span>
    </div>
    <br>

    <div class = "form-element">
        <label class = "enquiryLabel">Enquiry:</label>
        <textarea rows = "16" cols = "50" placeholder = "enter your enquiry here"  class = "input" id = "strEnquiry" name = "requestField" onkeyup = "valEnquiry();" onchange = "valEnquiry();"></textarea><span class='error' id="errorEnquiry">*</span>
    </div>

    <br>

    How should we contact you?<span class='error' id="errorRadio">  *</span>
    <br>
    <br>

    Phone:
    <input type = "radio" name = "radioPhone" id = "radioPhone" onclick = "uncheck('radioEmail');">
    <br>
    Email:
    <input type = "radio" name = "radioEmail" id = "radioEmail" onclick = "uncheck('radioPhone');">

    <br>
    <br>

    <input type = "submit" class = "subresButtons" name = "buttonSubmit" id = "buttonSubmit" value = "Submit">
    <input type = "reset" name = "subresButtons" id = "buttonReset" value = "Reset Form" onclick="window.location.reload();"><span class="errorHelp">(*) required fields</span>
</form>

Can anyone see why its not emailing me?

Cheers

Edited by [NOPE]FOREVER: accidentally submitted

Votes + Comments
tested
is this even a script, your good!
4
Contributors
4
Replies
73
Views
3 Years
Discussion Span
Last Post by imti321
0

i just teseted yor code and both mails were sent. Problem is elsewhere then i would say

7

I just figured it out. It seems that gmx does not support php for some odd reason

Votes + Comments
tested
it dosent have the right 2ct scripts enabled for rjsc6 te comms
0

The code you posted works fine as you may no the problem is offcourse somewhere else. The PHP mailer is so simple here no doubt, so it should work.

Have you tried it on any server or just on local machine?

0

i changed these lines and no errors now but it still dosent send mail

if (!$_POST['name']) {
        $errors[] = 'Please enter your name';
    }
    // Check if email has been entered and is valid
    if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        $errors[] = 'Please enter a valid email address';
    }
    //Check if message has been entered
    if (!$_POST['message']) {
        $errors[] = 'Please enter your message';
    }
    //  Check if simple anti-bot test is correct
    if (!$human = 5) {
        $errors[] = 'Your anti-spam is incorrect';
    }
    // Check for errors!
    if ($errors) {
        echo '<p class="errors">';
        foreach ($errors as $error) {
            echo 'Error: ' . $error . '<br>';
        }
        echo '</p>';
    }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.