我尝试在我的联系页面中设置表单,用户可以通过邮件将反馈发送给我。这里的问题是收到邮件,但页面没有刷新,没有警报框来帮助解决这个问题 我的Php代码 -
<?php
if (isset($_POST['submit']))
{
//print_r($_POST);
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$to='xyz@gmail.com';
//$subject='Send mail using php';
//$message='This mail send using php';
$headers="From: $name";
$mail=mail($to,$name,$email,$message);
if($mail)
{
echo'Mail send successfully';
}
else
{
echo'Mail is not send';
}}
?>
我的表格是 -
<form name="" action="" method="post" class="wpcf7-form">
<div class="row">
<div class="form-group col-xs-12 col-sm-12 col-md-6 col-lg-6">
<label>Your Name</label><br />
<input type="text" name="name" id="name" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required form-control" placeholder="Your name..." />
</div>
<div class="form-group col-xs-12 col-sm-12 col-md-6 col-lg-6">
<label>Phone</label><br />
<input type="text" id="phone" name="phone" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email form-control" placeholder="Phone number..." />
</div>
</div>
<div class="row">
<div class="form-group col-xs-12 col-sm-12 col-md-6 col-lg-12">
<label>Email Address</label><br />
<input type="text" id="email" name="email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email form-control" placeholder="Email Address..." />
</div>
</div>
<div class="form-group">
<label>Message</label><br />
<textarea name="message" id="message" cols="40" rows="10" class="wpcf7-form-control wpcf7-textarea wpcf7-validates-as-required form-control"></textarea>
</div>
<input type="submit" id="submit" name="submit" value="Send Message" class="wpcf7-form-control wpcf7-submit submit_btn" />
</form>
答案 0 :(得分:1)
请参阅PHP mail功能
$mail=mail($to,$subject,$message,$header);
如果您想创建如下警告更改代码。
$mail=mail($to,$subject,$message,$header);
if($mail)
{
?>
<script type='text/javascript'>alert("Mail sent");</script>
<?php
}
else
{
?>
<script type='text/javascript'>alert("Mail is not send");</script>
<?php
}
答案 1 :(得分:1)
如果您希望将消息显示为警报,则可以执行以下操作:
$mail = mail($to,$subject,$message,$header);
?>
<script>
alert('<?php echo $mail ? "Mail sent successfully" : "Mail was not sent" ?>');
</script>
答案 2 :(得分:0)
对于js警告检查以下代码
if($mail)
{
echo'<script>alert("Mail send successfully");</script>';
}