我是一名刚接触编码的人,刚刚开始学习项目。
这是一个网站。在电子邮件联系表单中,单击“提交”后,它不会将邮件发送到我的电子邮件,但它会保留在同一页面上。 我的操作系统是Ubuntu,文件都在opt / lamp / hotdocs / project文件夹中。 Apache和Mysql都在运行。 在PHP代码下面,它位于前端文件的同一文件中:
<?php
$statusMsg = '';
$msgClass = '';
if(isset($_POST['submit'])){
// Get the submitted form data
$email = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['message'];
// Check whether submitted data is not empty
if(!empty($email) && !empty($name) && !empty($message)){
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
$statusMsg = 'Please enter your valid email.';
$msgClass = 'errordiv';
}else{
// Recipient email
$toEmail = 'dilerniag@gmail.com';
$emailSubject = 'Contact Request Submitted by '.$name;
$htmlContent = '<h2>Contact Request Submitted</h2>
<h4>Name</h4><p>'.$name.'</p>
<h4>Email</h4><p>'.$email.'</p>
<h4>Message</h4><p>'.$message.'</p>';
// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: '.$name.'<'.$email.'>'. "\r\n";
// Send email
if(mail($toEmail,$emailSubject,$htmlContent,$headers)){
$statusMsg = 'Your contact request has been submitted successfully !';
$msgClass = 'succdiv';
}else{
$statusMsg = 'Your contact request submission failed, please try again.';
$msgClass = 'errordiv';
}
}
}else{
$statusMsg = 'Please fill all the fields.';
$msgClass = 'errordiv';
}
}
?>
然后是Contact.php页面,这只是代码的感兴趣部分:
<div id="contact" class="container">
<?php if(!empty($statusMsg)){ ?>
<p class="statusMsg <?php echo !empty($msgClass)?$msgClass:''; ?>"><?php echo $statusMsg; ?></p>
<?php } ?>
<form action="" method="post">
<h2 class="text-center">CONTACT</h2>
<div class="row">
<div class="col-sm-5">
<p>Contact us</p>
<p><span class="glyphicon glyphicon-map-marker"></span> Swords, North County, Dublin</p>
<p><span class="glyphicon glyphicon-phone"></span> +00353 018904452</p>
<p><span class="glyphicon glyphicon-envelope"></span> community.garde@gmail.com</p>
</div>
<div class="col-sm-7 slideanim">
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="name" name="name" placeholder="Name" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required>
</div>
</div>
<textarea class="form-control" id="message" name="message" placeholder="Message" rows="5" value="Click to send your comments"></textarea><br>
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right" type="submit">Send</button>
</div>
</div>
</div>
</div>
</div>
</form>
可能是什么问题? 谢谢。