通过PHP引导电子邮件发送器

Bootstrap Email Sender via PHP

本文关键字:电子邮件 PHP 通过      更新时间:2023-09-26

我试图使用bootstrap有一个模态弹出,让用户输入他们的电子邮件和消息。我已经有模态工作和显示2个字段。当用户单击send时,我希望将这两个字段的内容传递到服务器上的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文件对吗?

你像这样发送数据:

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>