出现联系表单消息但没有电子邮件

时间:2013-03-20 23:54:35

标签: php forms input

我已经构建了一个联系表单,但问题是,有时它发送消息,有时它不会,我已经在网站上添加了一个搜索栏,并且设置了输入提交按钮的不同,这可能是干预吗?

这是代码。

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: info@epicconcepts.nl'; 
$to = 'info@epicconcepts.nl'; 
$subject = 'Contact formulier bericht';
$human = $_POST['human']; 

$headers = "From: info@epicconcepts.nl\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "CC: quincynorbert@gmail.com\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$body = '<!DOCTYPE html>
<html>
  <head>
<style type="text/css">
  body
      {background: #fff;
  width:100%;
  height:auto;
  margin: 0;}
  #header-mail{background:#110f10;
  width:650px;
  height:70px;
  margin: 0 auto;}
  #content{background:#fff;
  width:630px;
  height:auto;
  padding: 20px;
  word-wrap:break-word;
  margin: 0 auto;}
  .mail-text{font-family:arial;
  color:#808080;
  font-size:12pt;
  line-height:130%;
  margin: 0 auto;
  text-align: left;}
  .bold{font-family:arial;
  color:#1f669a;
  font-size:14pt;
  font-weight:bold;
  margin: 0 auto;
  text-align: left;}
</style>
  </head>
<body>
  <center>
<img src="http://k2stuc.nl/img/bg-mailer.jpg" alt="Header" />
<div id="content">
      <p class="bold">'.$name.'<br>'.$email.'</p><br>
      <p class="mail-text">'.nl2br($message).'</p> 
</div>
<a href="http://www.k2stuc.nl">
<img src="http://k2stuc.nl/img/mailer-footer.jpg" alt="Footer" />
</a>
  </center>
</body>
</html>';
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '4') {                 
if (mail ($to, $subject, $body, $headers)) { 
echo '<p class="correct-message">Uw bericht is succesvol verzonden!</p>';
} else { 
echo '<p class="correct-message">Er is iets verkeerd gegaan, probeer het nog eens!</p>'; 
} 
} else if ($_POST['submit'] && $human != '4') {
echo '<p class="correct-message">U heeft de veiligheidsvraag verkeerd beantwoord!</p>';
}
} else {
echo '<p class="correct-message">U heeft niet alle verplichte velden ingevuld!</p>';
}
}
?>

        <form method="post" action="contact.php">

            <label>Naam</label>
            <input name="name" placeholder="Type hier">

            <label>Email</label>
            <input name="email" type="email" placeholder="Type hier">

            <label>Bericht</label>
            <textarea name="message" placeholder="Type hier"></textarea>

            <label>Hoeveel is 2+2?</label>
            <input name="human" placeholder="Type hier">

            <input id="submit" name="submit" type="submit" value="Verzend">

        </form>

1 个答案:

答案 0 :(得分:1)

试一试。我评论了几行。在使用我自己的电子邮件进行测试后,我发送了10封测试电子邮件,其中包含以下代码并将其全部收到。

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// $from = 'From: info@epicconcepts.nl'; // COMMENTED OUT - conflicting
$to = 'info@epicconcepts.nl'; 
$subject = 'Contact formulier bericht';
$human = $_POST['human']; 

$headers = "From: info@epicconcepts.nl\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
// $headers .= "CC: quincynorbert@gmail.com\r\n"; // Commented out for testing. May be a problem
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$body = '<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body{background: #fff;
width:100%;
height:auto;
margin: 0;}
#header-mail{background:#110f10;
width:650px;
height:70px;
margin: 0 auto;}
#content{background:#fff;
width:630px;
height:auto;
padding: 20px;
word-wrap:break-word;
margin: 0 auto;}
.mail-text{font-family:arial;
color:#808080;
font-size:12pt;
line-height:130%;
margin: 0 auto;
text-align: left;}
.bold{font-family:arial;
color:#1f669a;
font-size:14pt;
font-weight:bold;
margin: 0 auto;
text-align: left;}
</style>
</head>
<body>
<center>
<img src="http://k2stuc.nl/img/bg-mailer.jpg" alt="Header" />
<div id="content"><p class="bold">'.$name.'<br>'.$email.'</p><br><p class="mail-text">
'.nl2br($message).'</p> 
</div>
<a href="http://www.k2stuc.nl">
<img src="http://k2stuc.nl/img/mailer-footer.jpg" alt="Footer" />
</a>
</center>
</body>
</html>';

if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '4') {                 
if (mail ($to, $subject, $body, $headers)) { 
echo '<p class="correct-message">Uw bericht is succesvol verzonden!</p>';
} else { 
echo '<p class="correct-message">Er is iets verkeerd gegaan, probeer het nog eens!</p>'; 
} 
} else if ($_POST['submit'] && $human != '4') {
echo '<p class="correct-message">U heeft de veiligheidsvraag verkeerd beantwoord!</p>';
}
} else {
echo '<p class="correct-message">U heeft niet alle verplichte velden ingevuld!</p>';
}
}
?>