weixin_33701617 2017-02-19 12:41 采纳率: 0%
浏览 6

PHP邮件发送ajax [重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail" dir="ltr">PHP mail function doesn't complete sending of e-mail</a>
                            <span class="question-originals-answer-count">
                                (26 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2017-02-20 19:11:24Z" class="relativetime">3 years ago</span>.</div>
        </div>
    </aside>

I have a problem this PHP send mail.

I have this form in index.php page:

<form action="">
<input placeholder="Name" class="form" id="name" type="text" required/>
<input placeholder="Email" class="form" id="mail" type="email" required />
<input placeholder="Object" class="form" id="object" type="text" required />
<textarea placeholder="Type here..." id="text" class="form"></textarea>
<input class="formBtn" type="submit" id="submit"/>
<input class="formBtn" type="reset" />

This script on bottom of the index.php

<script>
$('#submit').click(function() {
    var nameform = $('#name').val();
    var mailform = $('#mail').val();
    var objectform = $('#object').val();
    var textform = $('#text').val();
    var mailcomplete = 'Name='+nameform+'Mail='+mailform+'Object='+objectform+'Message='+textform;

    $.ajax({
        type: "POST",
        url: 'php/mail.php',
        data: mailcomplete,
        success: function() {
            alert("Mail send OK!");
        }

    });
});

and this in php/mail.php

 <?php

$name = $_POST["nameform"];
$mail = $_POST["mailform"];

mail($mail, $name, "Hello!");

?>

But don't work... Can you help me? Tnk

</div>
  • 写回答

2条回答 默认 最新

  • weixin_33726313 2017-02-19 12:47
    关注

    Change your php/mail.php to this:

    <?php
    
    $name = $_POST["Name"];
    $mail = $_POST["Mail"];
    
    mail($mail, $name, "Hello!");
    
    ?>
    

    Also in your script in the index.php file, change:

    var mailcomplete = 'Name='+nameform+'Mail='+mailform+'Object='+objectform+'Message='+textform;
    

    to

    var mailcomplete = 'Name='+nameform+'&Mail='+mailform+'&Object='+objectform+'&Message='+textform;
    

    That should work. The problem was that you are passing the variables Name and Mail in data and not nameform and mailform. Also, the data formatting was incorrectly done in the script. Lemme know if it still doesn't work.

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题