我有一个模态表单,我正在通过图像点击进行的页面上调用。模态表单应该出现,我可以填写信息,点击提交,然后进入" process.php"要通过电子邮件发送给我的文件。
process.php文件将返回已发送电子邮件的信息,但它永远不会发送。
当它发出消息发送时,没有任何回声。
<a data-toggle="modal" data-target="#myModal" href="#"><img src="http://ashlardev.byethost17.com/images/shoplevel.png" class="img-square pull-right"></a>
<div class="modal fade custom-class" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Complete the form below to setup your <br>FREE account to view Le-Vel Products:</h4>
</div>
<div class="modal-body">
<form id="modal_feedback" method="POST" action="/process.php" accept-charset="UTF-8">
<p><label>Your Name<strong>*</strong><br>
<input type="text" autofocus required size="48" name="name" value=""></label></p>
<p><label>Email Address<strong>*</strong><br>
<input type="email" required title="Please enter a valid email address" size="48" name="email" value=""></label></p>
<p><label>Telephone<br>
<input type="tele" size="48" name="tele" value=""></label></p>
</form>
</div>
<div class="modal-footer">
*This information will not be shared with anyone other than Le-Vel.
<a href="/process.php" class="btn btn-success" type="submit" value="Send!" id="submit">Submit</a>
<a href="index5.html" class="btn btn-success" data-dismiss="modal">Nah.</a>
</div>
<?php
require_once('PHPMailerAutoload.php');
require_once('class.phpmailer.php');
require_once('class.smtp.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.openmailbox.org"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = false; // enable SMTP authentication
$mail->Host = "smtp.openmailbox.org"; // sets the SMTP server
$mail->SMTPSecure = 'TLS'; // Enable encryption, 'ssl' also accepted
$mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS
$mail->Username = "username"; // SMTP account username
$mail->Password = "password"; // SMTP account password
//add the recipient's address here
$myemail = 'my@address.com';
$mail->addAddress('my@address.com', 'Ford Christopher');
//grab named inputs from html then post to #thanks
if (isset($_POST['name'])) {
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$tele = strip_tags($_POST['tele']);
$body = "this is the body of my message: $name, $email, $tele";
$email_subject = "Le-Vel Free Account Information";
//generate email and send!
$headers = 'From: '.$email"\r\n".
'Reply-To: '.$email"\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($myemail, $email_subject, $body, $headers);
}
if($mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
echo $name;
echo $email;
echo $tele;
echo $body;
} else {
echo 'Message has been sent';
echo $name;
echo $email;
echo $tele;
echo $body;
}
?>
答案 0 :(得分:1)
有一系列错误。首先,不要永远使用@
来抑制您的功能。而是正确地测试并处理它:
if(!mail($myemail, $email_subject, $body, $headers)) {
echo "failed";
}
其次,你if($mail->send())
条件错了。你有错误的方法:
if($mail->send()) {...
== TRUE
if(!$mail->send()) {...
== FALSE
所以你希望你的比较看起来像这样:
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
//... the rest..
} else {
echo 'Mail sent successfully';
}
由于您的“提交”只是指向<a>
页面的process.php
链接,因此无法发送。
您需要正确地重新构建表单,否则不会提交任何输入元素。因此,为什么不发送邮件。
<div class="modal fade custom-class" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Complete the form below to setup your <br>FREE account to view Le-Vel Products:</h4>
</div>
<form id="modal_feedback" method="POST" action="/process.php" accept-charset="UTF-8">
<div class="modal-body">
<p><label>Your Name<strong>*</strong><br>
<input type="text" autofocus required size="48" name="name" value=""></label></p>
<p><label>Email Address<strong>*</strong><br>
<input type="email" required title="Please enter a valid email address" size="48" name="email" value=""></label></p>
<p><label>Telephone<br>
<input type="tele" size="48" name="tele" value=""></label></p>
</div>
<div class="modal-footer">
*This information will not be shared with anyone other than Le-Vel.
<input type="submit" class="btn btn-success" name="submit" value="Send!" id="submit">
<a href="index5.html" class="btn btn-success" data-dismiss="modal">Nah.</a>
</div>
</form>
</div>
</div>
</div>
你会注意到我是如何移动表单元素以包住.modal-body
&amp; .modal-footer
;允许您实际拥有submit
输入元素。