2017-01-02 23 views
1

我試圖發送電子郵件,其中部分來自變量,部分爲預設。 電子郵件到達罰款時,它只是設置爲文本或只是一個變量,但只要我嘗試並使用它永遠不會到達。 我已經證實所有的變量都是通過在最後回顯而正確的,但它實際上並沒有真正到達我的郵箱。PHP郵件 - 使用變量和純文本時郵件未到達

的代碼很可能不是做事情的最好方法,因爲我沒有做了很多編碼了幾年,但如果有人能告訴我,爲什麼發生這種情況我們將不勝感激:

   <?php 
       $action=$_REQUEST['action']; 
       if ($action=="") /* display the contact form */ 
        { 
        ?> 
        <form action="" method="POST" enctype="multipart/form-data" id="emailform"> 

         <input type="hidden" name="action" value="submit"> 

         <label for="contact_name">Name <span>*</span></label>       
         <input name="name" type="text" value="" size="30"/><br> 

         <label for="email">Email <span>*</span></label>       
         <input name="email" type="text" value="" size="30"/><br> 

         <label for="contact_name">Why can't you pay? <span>*</span></label>       
         <input name="nopay" type="text" value="" size="30"/><br> 

         <input class="submit-button" type="submit" value="Send Email" id="submit" name="submit"> 
        </form> 
        <?php 
        } 
       else    /* send the submitted data */ 
        { 
        $name=$_REQUEST['name']; 
        $email=$_REQUEST['email']; 
        $message='Why cant you pay '. $_REQUEST['nopay']; 
        if (($name=="")||($email=="")||($message=="")) 
         { 
         echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
         } 
        else{  
         $from="From: $name<$email>\r\nReturn-path: $email"; 
         $subject="Sacred Arts Camp Enquiry"; 
         mail("[email protected]", $subject, $message, $from); 

         echo "<p>Thanks for your email!<br/>Someone will pick it up shortly and be in touch to help you out.</p>"; 
         } 
        } 
       ?> 
+0

它是否得到'回聲「

感謝您的電子郵件!
有人會很快接受並聯系,以幫助您。

」;'所有的時間? – Rasclatt

+0

是的,它的確如此。當我測試以確保所有變量都是正確的時候,我將它們放在後面,他們也在顯示。 –

+0

嘗試'if(mail(「[email protected]」,$ subject,$ message,$ from))echo'Sent';'看看它是否寫入'Sent' – Rasclatt

回答

0

請把這段代碼放在

else 
{ 
     $to = $email; // Send email to our user 
     $subject = 'Sacred Arts Camp Enquiry'; // Give the email a subject 
     $message = ' your message';      
     $headers = 'From:www.yourwebsite.com' . "\r\n"; // Set from headers 
     mail($to, $subject, $message, $headers); // Send our email  
} 

請嘗試使用在線服務器。

+0

Thanks對於Mohit的迴應,但它沒有任何區別。 –

+0

您使用的是wamp服務器嗎? –

+0

這是一個活的域名。 –