drouie2014 2016-07-18 08:25
浏览 11

PHP Mail不使用AJAX发送邮件[重复]

This question already has an answer here:

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
";
$headers .= "Content-type: text/html
";
$emailSubject = "$his_name and $her_name Honeymoon Review";
$emailTo = $email1;

if(mail($emailTo, $emailSubject, $body, $headers)) 
    echo "Successful";
else
    echo "Unsuccessful";
?>
</div>
  • 写回答

1条回答 默认 最新

  • duanqianhuan3994 2016-07-18 09:07
    关注

    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
    ";
    $headers .= "From: calcutt5@box996.bluehost.com
    ";
    

    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.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度