尝试发送不显示任何错误消息的电子邮件或只刷新该页面的任何内容。
我正在尝试通过联系表单发送电子邮件,但它不起作用。这是代码。尝试做回声,但它没有工作。也没有显示任何错误。
联系和联系:
<?php ob_start();
if(isset($_POST['submit'])) {
$to = "abc@gmail.com";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$txt = $_POST['comment'];
$headers = "From: " .$email . "\r\n" .
"CC: xyz@gmail.com";
mail($to,$subject,$txt,$headers);
header("Location: contact.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>HMS System</title>
</head>
<body>
<div class="container">
<div class="page-header">
<h2>Contact Us Form</h2>
</div>
<form class="form-horizontal" action="contactus.php" method="post" role="form">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="name" placeholder="Insert your Name" id="name">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email Address</label>
<div class="col-sm-8">
<input type="email" class="form-control" name="email" placeholder="Email Address" id="email">
</div>
</div>
<div class="form-group">
<label for="subject" class="col-sm-2 control-label">Subject</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="subject" placeholder="Subject" id="subject">
</div>
</div>
<div class="form-group">
<label for="comments" class="col-sm-2 control-label">Comment</label>
<div class="col-sm-8">
<textarea class="form-control" rows="10" name="comment" style="resize:none;"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-8">
<input type="submit" value="Send Message" name="submit_contact" class="btn btn-block btn-danger" id="subject">
</div>
</div>
</form>
</section>
</article>
</div>
<div style="width:50px;height:50px;"></div>
</body>
答案 0 :(得分:0)
使用此
if(isset($_POST['submit_contact']))
答案 1 :(得分:0)
如果您是从本地服务器执行此操作,则必须在ini中正确设置邮件,然后才能从本地计算机发送邮件。
答案 2 :(得分:0)
更好的方法是将string filepath = Server.MapPath(your text file path);
string content = string.Empty;
using (var stream = new StreamReader(filepath)) {
content = stream.ReadToEnd();
}
ViewBag.context = content;
函数包装在语句中。邮件返回mail
值。 并尽可能简单地开始。
bool
验证您是否收到error_reporting (E_ALL);
$to = "mail@whatever.com"
// ... your settings ...
if ( mail ( $to , $subject , $message ) ) {
// do when ok
}
else {
// do when error
}
的所有值
$_POST