通过PHP引导电子邮件发件人

时间:2014-03-20 22:01:16

标签: javascript php twitter-bootstrap

我正在尝试使用bootstrap弹出模式,让用户输入他们的电子邮件和消息。我已经有模态工作并显示2个字段。当用户点击发送时,我希望将这两个字段的内容传递到我服务器上的php文件。

我的模态代码:

      <!--Email Modal-->
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;  </button>
    <h4 class="modal-title" id="myModalLabel">Contact Me</h4>
   </div>
   <div class="modal-body higher">

     <div class="input-group">
     <span class="input-group-addon">Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
     <input type="text" class="form-control" placeholder=" Enter your email address..">
    </div>

    <br>

     <div class="input-group">
     <span class="input-group-addon" >Message:</span>
    <textarea class="form-control"  rows="10"></textarea>

    </div>



  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
    <button type="button" class="btn btn-primary"        onclick="http://www.example.com/dist/php/SendEmail.php?sender=mysender&body=mybody">Send Email</button>
  </div>
</div>
</div>
</div>

该php文件的内容是:

<?php
$recipient = $_POST["myemail@email.com"];
$sender = $_POST["sender"];
$body =  $_POST["body"];
$headers = 'From: sample@sample.com' . "\r\n" .
'Reply-To: sample@sample.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

$sendMail = mail($recipient, $sender, $body, $headers);

if( $sendMail == true )  
{
  echo "Message sent successfully...";
}
else
{
  echo "Message could not be sent...";
}

?>

我觉得错误可能在于点击发送按钮,或者我没有将值传递给php文件吗?

1 个答案:

答案 0 :(得分:0)

您发送的数据如下:

http://www.example.com/dist/php/SendEmail.php?sender=mysender&body=mybody

使用$_GET而不是$_POST

$sender = $_POST["sender"];

您还试图提交其他数据,例如电子邮件地址。您混合了$_POST$_GET。您应该将其包装在form标记中并将其提交到您的php脚本。

编辑:再次查看后,您的javascript错误,请使用此...

<button onclick="location.href = 'http://www.example.com/dist/php/SendEmail.php?sender=mysender&body=mybody';" class="btn btn-primary">Send Email</button>