1

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

这是代码。

<?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>
4

1 回答 1

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>';
}
}
?>
于 2013-03-21T00:43:21.460 回答