2014-09-13 40 views
-2
if (isset($_REQUEST['email'])) { 

    //Email information 
    $admin_email = "[email protected]"; 

    $name = $_REQUEST['name']; 

    $email = $_REQUEST['email']; 

    $subject = $_REQUEST['subject']; 

    $comment = $_REQUEST['comment']; 




    //send email 

    mail($admin_email, $name, "$subject", $comment, "From:" . $email); 

    //Email response 

    echo "Thank you for contacting us!"; 
    } 

    //if "email" variable is not filled out, display the form 

    else { 

      ?> 

<form method="post"> 

            <div> 
           <span><input name="name" type="text" class="textbox" value="Name:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name*';}"></span> 
          </div> 

          <div> 
           <span><input name="email" type="text" class="textbox" value="Email:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email*';}"></span> 
          </div> 




          <div> 
           <span><input name="subject" type="text" class="textbox" value="mobile:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'subject and phone*';}"></span> 
          </div> 

          <div> 
           <span><textarea name="comment" value="Message:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Message*';}">Message</textarea></span> 
          </div> 

          <div> 
           <span><input type="submit" value="Submit"></span> 
          </div> 
<?php } ?> 
+1

問題是什麼? '不工作'不會告訴我們你的問題 – SuperDJ 2014-09-13 18:00:23

+0

當你運行這段代碼時會發生什麼?一個錯誤?沒有?錯誤的人會收到電子郵件?沒人做到?錯誤的文字被髮送? – andrewsi 2014-09-13 18:00:50

+0

沒有收到我指定的郵件$ admin_email =「[email protected]」; – 2014-09-13 18:03:07

回答

0

對於mail(),您有錯誤的參數。嘗試了這一點:

mail($admin_email, $subject, $comment, "From: " . $email); 

他們需要$to, $subject, $message,而你不得不$to, $name, $subject, $message(不包括可選參數)。

+0

但我想在其中添加5個變量。爲什麼我不能使用這個郵件($ admin_email,$ name,$ subject,$ comment,「From:」。$ email); mail($ admin_email,$ subject,$ comment,「From:」。$ email);此功能不工作仍然我沒有收到此電子郵件[email protected] – 2014-09-13 18:14:20

+0

您可以通過添加它在消息中添加名稱,但不是作爲一個單獨的參數。 'mail($ admin_email,$ subject,$ name。「寫道:」。$ comment,「From:」。$ email);'會工作。注意它只是一個參數。 – 2014-09-13 18:16:38

+0

郵件($ admin_email,$ subject,$ name。)寫道如下:「。$ comment,」From:「。$ email); 此功能仍然不能正常工作:( 請自行嘗試,並讓我知道 – 2014-09-13 18:23:10