0

I am trying to set up a simple email function in php. Looking through the other questions that address the same issue, it appears that I'm doing the same thing the answers are saying to do. However, when I try to send the email, it doesn't send.

HTML

<form id="contactMeForm">
    <div class="formField">
        <label for="senderName">Name:</label>
        <input type="text" id="senderName" class="textField" placeholder="Your name" />
    </div>
    <div class="formField">
        <label for="senderEmail">Email:</label>
        <input type="text" id="senderEmail" class="textField" placeholder="Your email" />
    </div>
    <div class="formField">
        <label for="contactReason">Contact reason:</label>
        <select id="contactReason">
            <option></option>
            <option>I'd like a quote for a website.</option>
        </select>
    </div>
    <div class="formField" id="message">
        <div id="senderPhone">
            <label for="returnPhone">Contact number:</label>
            <input type="text" id="returnPhone" class="textField" placeholder="Best phone number to reach you at." />
        </div>
        <label for="senderMessage">Message:</label>
        <textarea id="senderMessage"></textarea>
    </div>

JS

$.ajax({
    type: "POST",
    url: "scripts/email.php",
    data: {name: senderName, email: senderEmail, reason: contactReason, phone: returnPhone, message: senderMessage},
    dataType: "json",
    success: function(response){
        contactMeForm.style.display = "none";
        formButtons.style.display = "block";
        confirmMessage.style.display = "block";
        buttons[1].style.display = "none";
        contactMeHeader[0].textContent = "Your message has been sent.";
    }
})

PHP

<?php
    $name = $_POST["name"];
    $email = $_POST["email"];
    $reason = $_POST["reason"];
    $phone = $_POST["phone"];
    $headers = "From: " .$email ."\r\n";
    $message = $_POST["message"];

    mail("[email protected]", $reason, $message, $headers);
    echo json_encode(array($name, $email, $reason, $phone, $message));
?>

php.ini

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 25

I'm running an Apache server with EasyPHP on a Windows machine. I'm also not getting any error messages.

1 Answer 1

2

I'm guessing none of the fields are populating. You need to add the name property to each of the fields, that's what PHP is looking for in the $_POST array.

<input type="text" id="senderEmail" class="textField" placeholder="Your email" name="email" />
1
  • Ah, gotcha. Thank you
    – user4720622
    Sep 17, 2016 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.