0

Good day, so I've stumbled upon this very easy problem for you pros out there. To note, I have been researching for this problem but I just don't understand why this is not working. So what I'm doing is I'm trying to make a review form successfully send a mail to my email. So here's my code:

HTML

<input type="text" id="his-name" name="his-name" placeholder="His name*">
<input type="text" id="her-name" name="her-name" placeholder="Her name*">
<input type="text" id="location" name="location" placeholder="Location of honeymoon*">
<textarea id="fav-moment" name="fav-moment" placeholder="Favorite moment during the trip"></textarea>  
<textarea id="review" name="review" placeholder="Please write a short review of your experience*"></textarea>
<p>Upload few pictures from your honeymoon <span style="display: block; font-size:.7em">Please upload only a maximum of 4 photos</span></p><br/>

<form action="<?php echo get_template_directory_uri(); ?>/upload.php?sessionid=<?php echo $_SESSION['sessionid'] ?>"
             class="dropzone" id="my-awesome-dropzone"></form>

JS

$(document).ready(function () {
showMenu();

$('#submit-feedback').click(function (e) {
    e.preventDefault();
    ajax_send_feedback();
});

function ajax_send_feedback() {
$('#contact-msg-f').html('<i style="font-size:2em;" class="fa fa-spinner fa-spin"></i>');
var errors = new Array();
errors = validate_feedback_form();
if (errors.length != 0) {
    display_feedback_errors(errors);
    feedbackDelivered(0);
    return;
}
else {
    // Send data for server validation
    $.get("http://atravelduet.com/process-review-form.php", {
        hisname: $('#his-name').val(),
        hername: $('#her-name').val(),
        location: $('#location').val(),
        favmoment: $('#fav-moment').val(),
        review: $('#review').val(),
        url: $('#url').val()
    }).done(function (response) {
            if (!response) {
                feedbackDelivered(1);
                clearFields(); **//THIS IS NOT WORKING TOO :(**
            }
            else {
                var errros = new Array();
                errors = $.parseJSON(response);
                if (errors.length != 0) {
                    display_feedback_errors(errors);
                    feedbackDelivered(0);
                }
            }
        });
    }
}

function feedbackDelivered(res) {
if (res == 1) {
    $('#contact-msg-f').html('<span style="color:#00ff00;">Message Sent!</span>');
}
else {
    $('#contact-msg-f').html('<span style="color:#ff0000;">Please correct the fields marked red!</span>');
}
}

PHP

<?php
$email0 = 'codeaxiscom@gmail.com';
$email1 = 'jjmaranga05@gmail.com';

$his_name = $_POST['hisname'];
$her_name = $_POST['hername'];
$location = $_POST['location'];
$fav_moment = $_POST['favmoment'];
$review = $_POST['review'];

$body = <<< EOD
<br><hr><br>
His Name: $his_name<br>
Her Name: $her_name<br>
Location: $location<br>
Favorite Moment: $fav_moment<br>
Review: $review<br>
EOD;

$headers = "From: calcutt5@box996.bluehost.com\r\n";
$headers .= "Content-type: text/html\r\n";
$emailSubject = "$his_name and $her_name Honeymoon Review";
$emailTo = $email1;

if(mail($emailTo, $emailSubject, $body, $headers)) 
    echo "Successful";
else
    echo "Unsuccessful";
?>
Jude Maranga
  • 865
  • 2
  • 9
  • 27
  • And what isn't working? What errors are you getting? – Epodax Jul 18 '16 at 08:26
  • @Epodax actually, I get no errors. The feedbackDelivered() function works well (Like the function call with number 1 as parameter passed). I just don't get the email in my email – Jude Maranga Jul 18 '16 at 08:33

1 Answers1

0

At first you have an error because the mail() function returns FALSE. So no email is send.

Try to put "From" header after content-type like this

$headers = "Content-type: text/html\r\n";
$headers .= "From: calcutt5@box996.bluehost.com\r\n";

And check if it is working now. If it is not try completely comment the line with From header and check if it returns success and if you get an email.

The problem maybe that you are using bad "From" header. In most cases the email should be like the domain were the mail is sent from.

In addition i suggest you use for example a PHPMailer which is not hard to configure and it works much better and you have an error log so you can easily debug it.

mamosek
  • 316
  • 2
  • 6