Member Avatar

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

    $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($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 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 class = "form-element">
        <label>Select product:</label>
        <select id = "ddl2" onclick="valDDL2();" class = "input"  class = "ddl">
        </select><span class = 'error' id = "errorDDL2">*</span>

    <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 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 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 class = "form-element">
        <label>Contact Email:</label>
        <input type = "text" class = "input" name = "emailInput" placeholder = "" onkeyup = "valEmail();" onchange = "valEmail();" id = "strContactEmail"><span class='error' id="errorContactEmail">*</span>

    <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>


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

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


    <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>

Can anyone see why its not emailing me?


joyc123 commented: is this even a script, your good! +0
thelove commented: tested +0

Recommended Answers

All 4 Replies

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

Member Avatar

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

commented: it dosent have the right 2ct scripts enabled for rjsc6 te comms +0
commented: tested +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?

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>';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.