douye6812 2011-08-11 03:14
浏览 94

为什么这个AJAX调用正确的php脚本没有返回任何东西?

I posted a similar question earlier, just I did not realize that the code I put had an obvious bug in it (not supplying the data) which I new existed. Now I am redoing it with that because I am still having the problem.

I have this AJAX:

function sendMail(){
            $.ajax({
                type: "POST",
                url: "../prestige-auto/php/sendMail.php",
                data: {"message" : $('#contactMessage').html(),
                         "email" : $('#contactEmail').val(),
                         "name" : $('#contactName').val()},
                success: function(result){
                    if (result == 'success') {
                        alert(result);
                    } else {
                        alert(result);
                    }
                }
            });
        };

$('#submitContact').click(function(){
        sendMail();
    })

and this PHP:

<?php

$trimmed = array_map('trim', $_POST);

$message = $trimmed['message'];
$email = $trimmed['email'];
$name = $trimmed['name'];

if (empty($message)) {
    $message = FALSE;
}

if (empty($email)) {
    $message = FALSE;
}

if (empty($name)) {
    $message = FALSE;
}

if ($message && $email && $name){

    $body = "From: $name.
 
 $message";

    mail(/*some email*/, 'Website Contact Form Submission', $body, "From: $email");

    echo ('success');

}

echo($message.' '.$email.' '.$name);

?>

All the html elements defined exist. When I run it all that returns is a blank alert box (meaning that the PHP script did not print out success). Any idea why it is not sending the mail?

  • 写回答

3条回答 默认 最新

  • douzhi7451 2011-08-11 03:24
    关注

    Don't use array_map('trim', $_POST) http://www.php.net/manual/en/function.trim.php#96246

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持