简体   繁体   中英

Contact form message appears but no email

I have built a contact form but the problem is, sometimes it sends the message, and sometimes it wont, I have added a searchbar to the site and have styled that input submit button differently, can that be the interfearence?

Here's the code.

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

Give this a try. I commented out a few lines. After testing it with my own email, I sent out 10 test emails with the code below and received them all.

<?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>';
}
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM