[英]Bootstrap Email Sender via PHP
我正在嘗試使用引導程序來彈出模式對話框,並允許用戶輸入其電子郵件和消息。 我已經有模態工作並顯示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">× </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
使用$_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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.