duancan65665 2015-01-09 22:04
浏览 37
已采纳

Bootstrap JQuery向PHP邮件发布了错误的数据元素

I am writing a wedding website with a basic form to get the guest email address, guest name(s), guest dinner option, the number of children they are bringing, and a requested song they would like played. I then want to take these values and send them via PHP mail function to an email address. Here is what I have so far:

Here is the snippet of my javascript. The variables emailAddr, g1_name, and g1_dinner all have the correct values in them when I log it to the console.

var data = {
            email : emailAddr,
            g1Name : g1_name,
            g1Dinner : g1_dinner
            };

$.post("email.php", data, function(){
            alert("Email Success");
        });

Here is the PHP:

     <?php
            $to = "test@email.com";
            $from = $_POST['email'];
            $guestName_1 = $_POST['g1Name'];
            $guestDinner_1 = $_POST['g1Dinner'];
            $message = "Email: "+$from +"

Guest 1: "+$guestName_1+" - "+$guestDinner_1;
            $message = wordwrap($message, 70);

            mail($to,"Wedding RSVP",$message);
    ?>

Here is what is actually getting POST'd: enter image description here

And here is the email I get from my web host:

enter image description here

So my main question is why is what is getting POST to my PHP file different than I am specifying?

And a follow up, why am I getting emailed a 0 and not the string I set?

And is this the right way to do something like this?

Any help is appreciated! Thanks!

  • 写回答

1条回答 默认 最新

  • doushang2021 2015-01-09 22:06
    关注

    PHP 101: String concatenation uses ., you're using +, which is mathematical addition.

    'string' + 'string' => generally "0" or wonky integer as result
    'string' . 'string' => 'stringstring'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料