Javascript 通过PHP引导电子邮件发送者
我试图使用引导有一个模式弹出窗口,让用户输入他们的电子邮件和消息。我已经有模式工作和显示2个字段。当用户单击send时,我希望将这两个字段的内容传递到服务器上的php文件 我的模式代码:Javascript 通过PHP引导电子邮件发送者,javascript,php,twitter-bootstrap,Javascript,Php,Twitter Bootstrap,我试图使用引导有一个模式弹出窗口,让用户输入他们的电子邮件和消息。我已经有模式工作和显示2个字段。当用户单击send时,我希望将这两个字段的内容传递到服务器上的php文件 我的模式代码: <!--Email Modal--> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> &
<!--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">× </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: </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文件,对吗?您发送的数据如下所示:
http://www.example.com/dist/php/SendEmail.php?sender=mysender&body=mybody
使用$\u GET
而不是$\u POST
$sender = $_POST["sender"];
看起来您还试图提交其他数据,如电子邮件地址。您正在将POST和GET这两种方法混合使用。您应该将其包装在表单中
标记中,然后提交到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>
发送电子邮件
谢谢,不过还是没什么。有没有办法通过php将错误返回到服务器上的某个文件夹中?到底是什么不起作用?你没有收到电子邮件吗?看到错误?仍然没有收到任何电子邮件。我不确定如何调试它,我没有线索。。