2013-05-02 48 views
-1

我有錯誤拋出了我的聯繫表單。我不是太熟悉的PHP,所以這裏是我用於PHP和HTML的代碼。聯繫表格省略字段並踢出錯誤

的HTML:

<form name="contactform" method="post" action="sendmail.php" align="center"> 
<table width="450px" id="black2" style="background-color:#fff" align="center"> 
</tr> 
<tr> 
<td valign="top" id="black2"style="background-color:#fff"> 
    <label for="first_name" >First Name *</label> 
</td> 
<td valign="top"id="black2"> 
    <input type="text" name="first_name" maxlength="50" size="30" id="black2"> 
</td> 
</tr> 

<tr> 
<td valign="top"" id="black2"> 
    <label for="last_name" id="black2">Last Name *</label> 
</td> 
<td valign="top"> 
    <input type="text" name="last_name" maxlength="50" size="30"> 
</td> 
</tr> 
<tr> 
<td valign="top"> 
    <label for="email">Email Address *</label> 
</td> 
<td valign="top"> 
    <input type="text" name="email" maxlength="80" size="30"> 
</td> 

</tr> 
<tr> 
<td valign="top"> 
    <label for="telephone">Telephone Number</label> 
</td> 
<td valign="top"> 
    <input type="text" name="telephone" maxlength="30" size="30"> 
</td> 
</tr> 
<tr> 
<td valign="top"> 
    <label for="comments">Comments *</label> 
</td> 
<td valign="top"> 
    <textarea name="comments" maxlength="1000" cols="24" rows="6"></textarea> 
</td> 

</tr> 
<tr> 
<td colspan="2" style="text-align:center"> 
    <input type="submit" value="Submit"> 
</td> 
</tr> 
</table> 

這裏是PHP:

<?php 
$first_name = $_REQUEST['email']; 
$last_name = $_REQUEST['last_name']; 
$email = $_REQUEST['email']; 
$telephone = $_REQUEST['telephone']; 
$comments = $_REQUEST['comments']; 
mail("[email protected]","Feedback Form Results", $comments, $telephone, $first_name, 
$last_name, "From: $email"); 
header("Location: http://www.mywebsite.co.za/thankyou.html"); 
?> 

請你能幫助我儘快解決這個問題,因爲我跑的AdWords和人民正在設法聯繫。

說出來的形式的錯誤是: 「 Warning: mail() expects at most 5 parameters, 7 given in /home/wwwzeetu/public_html/sendmail.php on line 13

Warning: Cannot modify header information - headers already sent by (output started at /home/wwwzeetu/public_html/sendmail.php:13) in /home/wwwzeetu/public_html/sendmail.php on line 14

我感謝您的幫助!

+0

把ob_start();在你的代碼的第一行和[PHP郵件函數](http://www.w3schools.com/php/php_mail.asp)只接受5個參數,但我已經給出了7! 在主體參數中放置'$ telephone,$ first_name,$ last_name'。 – 6339 2013-05-02 08:30:15

回答

0
<?php 
    $first_name = $_REQUEST['email']; 
    $last_name = $_REQUEST['last_name']; 
    $email = $_REQUEST['email']; 
    $telephone = $_REQUEST['telephone']; 
    $comments = $_REQUEST['comments']; 
    // multiple recipients 
    $to = '[email protected]'; 
    // subject 
    $subject = 'Feedback Form Results'; 
    // message 
    $message='<html> 
     <head> 
      <title>Birthday Reminders for August</title> 
     </head> 
     <body> 
      <p>Here are the birthdays upcoming in August!</p> 
      <table> 
      <tr> 
       <td>First Name</td><td>'.$first_name.'</td> 
      </tr> 
      <tr> 
       <td>Last Name</td><td>'.$last_name.'</td> 
      </tr> 
      <tr> 
       <td>Telephone</td><td>'.$telephone.'</td> 
      </tr> 
      <tr> 
       <td>Comments</td><td>'.$comments.'</td> 
      </tr> 
      </table> 
     </body> 
     </html>'; 

    // To send HTML mail, the Content-type header must be set 
    $headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
    // Additional headers 
    $headers .= 'From: '.$email."\r\n"; 
    // Mail it 
    mail($to, $subject, $message, $headers); 
?> 

網址Mail

+0

嗨Rohan。非常感謝你。雖然我不知道如何將它放到我所需要的背景中,因爲我不知道PHP。我只是從網上的某個地方複製了一段代碼並將其應用到我的網站。它已經工作了其他人。 – Sash 2013-05-02 08:36:44

+0

嗨Rohan和Chandresh。我很抱歉向你這樣做。我想收集上述字段的信息。我將如何使用你的代碼這個 ? – Sash 2013-05-02 09:13:37

+0

@ user2261249檢查以上我已對我的答案進行了更改。 – 2013-05-02 09:32:27

0

ob_start(); 

在你的代碼的起始消除這種誤差。另外改變你的郵件功能它有太多的參數。所以,你的代碼更改爲

<?php 
ob_start(); 
$first_name = $_REQUEST['email']; 
$last_name = $_REQUEST['last_name']; 
$email = $_REQUEST['email']; 
$telephone = $_REQUEST['telephone']; 
$comments = $_REQUEST['comments']; 
//mail("[email protected]","Feedback Form Results", $comments, $telephone, $first_name, $last_name, "From: $email"); 
mail("[email protected]","Feedback Form Results","Test Mail",$comments, "From: $email"); 
header("Location: http://www.mywebsite.co.za/thankyou.html"); 
?> 
+0

謝謝Chandresh。這有效,沒有顯示錯誤,但郵箱中沒有顯示郵件?任何想法爲什麼? – Sash 2013-05-02 08:15:13

+0

可能是您的郵件服務器沒有設置。由您的郵件功能 – 2013-05-02 08:16:04

+0

在這裏是錯誤的。你傳遞的參數太多了。檢查我更新的答案 – 2013-05-02 08:17:10