<?php $errName = $errMessage=$errHuman=$result=$errEmail=""; if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = 'بخش ارتباط با ما';
$to = 'info@iranrtn.com';
$subject = 'پیام جدید';
$body ="From: $name\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
//Check if simple anti-bot test is correct
if ($human !== 5) {
$errHuman = 'Your anti-spam is incorrect';
}// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success text-center">با تشکر از شکیبایی شما به<a href="index.html"> خانه </a>بازگردید.</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
}
} } ?>
<body style="font-family: yekan"> <div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1 class="page-header text-center">جهت ارتباط با ما فرم زیر را پر کنید.</h1>
<form class="form-horizontal" role="form" method="post" action="contact.php">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">نام</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="نام و نام خانودگی" value="">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" value="ssss">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">پیام</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</div>
</div>
<div class="form-group">
<label for="human" class="col-sm-2 control-label">2 + 3 = ?</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="human" name="human" placeholder="پاسخ شما">
<?php echo "<p class='text-danger'>$errHuman</p>";?>
</div>
</div>
<div class="form-group">
<div >
<input id="submit" name="submit" type="submit" value="ارسال" class="btn btn-primary">
</div>
</div>
<div class="form-group">
<div >
<?php echo $result; ?>
</div>
</div>
</form>
</div> </div> </div> </body>
我尝试从我的网站的联系表单发送电子邮件到我的主机邮件(info@domain.com)我检查我的代码的每个部分,电子邮件地址创建正确,操作是好的但是当我按下发送按钮时显示错误我在Windows主机上没有此问题但在Cpanel主机上没有此问题是否有任何邮件设置配置? ps:此联系表单在另一个站点上运行。
文件contact.php在这里&gt;&gt; 所有在一个PHP文件 这是联系表格:http://iranrtn.com/contact.php