2013-03-20 83 views
1

我建立了一個接觸的形式,但問題是,有時它發出的消息,有時不會,我添加了一個搜索欄的網站,並稱呼該輸入不同的提交按鈕,可以那是干涉?接觸表現形式的消息,但沒有電子郵件

這是代碼。

<?php 
$name = $_POST['name']; 
$email = $_POST['email']; 
$message = $_POST['message']; 
$from = 'From: [email protected]'; 
$to = '[email protected]'; 
$subject = 'Contact formulier bericht'; 
$human = $_POST['human']; 

$headers = "From: [email protected]\r\n"; 
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n"; 
$headers .= "CC: [email protected]\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> 
+0

你有沒有看垃圾郵件箱? – hlegius 2013-03-21 00:00:42

+0

是的,那不是它a.lready檢查它,完全地隨機 – 2013-03-21 00:07:06

+0

嘗試改變單引號雙引號'$身體=「<!DOCTYPE HTML!>'和'」;' - 它已經起到了一定作用之前有很多形式的問題 – 2013-03-21 00:07:51

回答

1

試試看。我評論了幾行。在用我自己的電子郵件進行測試後,我發送了10封包含以下代碼的測試郵件,並收到了所有郵件。

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

$headers = "From: [email protected]\r\n"; 
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n"; 
// $headers .= "CC: [email protected]\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>'; 
} 
} 
?> 
相關問題