2017-12-03 173 views
0

我遇到了我的PHP代碼爲我的網站出現問題。電子郵件正在發送,但沒有消息。聯繫表格發送電子郵件,但沒有消息

This is the email I get when it sends. It's empty.

Data I input in my contact form

我測試我的PHP代碼,而無需在css文件和引導,並與收到的消息的電子郵件完美。但是當我把所有的東西都包含進去,從css和bootstrap代碼,我收到沒有任何消息的電子郵件。

HTML代碼:

<div class="contact-form bottom"> 
    <h2> We want to hear from you . Send us a message!</h2> 
    <form id="main-contact-form" name="contact-form" method="post" action="send_email_test.php"> 
     <div class="form-group"> 
      <input type="text" name="userName" class="form-control" required="required" placeholder="Name"> 
     </div> 
     <div class="form-group"> 
      <input type="email" name="userEmail" class="form-control" required="required" placeholder="Email Id"> 
     </div> 
     <div class="form-group"> 
      <textarea name="userMessage" id="message" required class="form-control" rows="8" placeholder="Your text here"></textarea> 
     </div> 
     <div class="form-group"> 
      <input type="submit" name="submit" class="btn btn-submit" value="Submit"> 
     </div> 
    </form> 
</div> 

這是我的PHP代碼:

<?php 
$field_name = $_POST['userName']; 
$field_email = $_POST['userEmail']; 
$field_subject = $_POST['userSubject']; 
$field_message = $_POST['userMessage']; 

$mail_to = '[email protected]'; /* Add your email address here */ 
$subject = 'Message from website'.$field_name; /* Create your own subject */ 

$body_message .= 'From: '.$field_name."\n"; 
$body_message .= 'Email: '.$field_email."\n"; 
$body_message .= 'Subject: '.$field_subject."\n"; 
$body_message .= 'Message: '.$field_message; 

$headers = 'From: '.$field_email."\r\n"; 
$headers .= 'Reply-To: '.$field_email."\r\n"; 

$mail_status = mail($mail_to, $subject, $body_message, $headers); 

if ($mail_status) { ?> 
<script language="javascript" type="text/javascript"> 
    alert('Hey! Thanks for the message! We will try to reply to you as soon as possible!'); 
    window.location = 'index.html'; /* Where you want to get directed */ 
</script> 
<?php 
} else { ?> 
<script language="javascript" type="text/javascript"> 
    alert('Sorry, your message was not sent! Please send an email to 
[email protected] instead.'); 
    window.location = 'index.html'; /* Where you want to get directed 
*/ 
</script> 
<?php 
} 
?> 

+1

檢查'$ _POST'是否有任何數據或一切爲空 –

+0

在電子郵件中,一切都是空白的。 –

+0

在電子郵件中,一切都是空白的,bcz'$ _POST'變量爲空。 –

回答

0

確認您的形式有正確的 「名稱」 屬性。 你的代碼很骯髒壽。

+0

一切都正確無誤。我測試了html和php,它工作得很好,但是當我用其他所有東西將它添加到我的網站時,電子郵件是空的。 –

+0

這真的很奇怪,你可以在發送電子郵件之前做一個vardump結果 –

+0

我試着在vardump中添加,然後表單不會發送。我很確定我是否做得對。值得一提的是,我的網站來自bootstrap模板? –

相關問題