2012-09-11 85 views
0

我想將我的HTML表單複製到電子郵件正文中。下面是表單已經在php文件中的代碼,但是如果用戶提交html表單文件,那麼所有不隱藏的表單數據都將被複制(作爲禁用的元素)在郵件正文中。此外,如果有任何文件附件字段,它應該被附加到電子郵件。在電子郵件中複製HTML表單PHP

<?php 
// multiple recipients 
$to = '[email protected]' . ', '; // note the comma 
$to .= '[email protected]'; 

// subject 
$subject = 'Birthday Reminders for August'; 

// message 
$message = ' 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 


<title>Untitled Document</title> 
</head> 

<body style="padding:3px; margin:0px;" bgcolor="#FFFFFF"> 
<table cellpadding="0" cellspacing="0" border="0" width="440"> 

    <tr><td style="height:10px"></td></tr> 
    <tr> 
     <td colspan="2" style="text-align:justify; line-height:15px;" class="body"> 

     <form name="frm" method="POST" action="careersuccess.php" enctype="multipart/form-data"> 
     <table cellpadding="0" cellspacing="0" border="0" width="100%"> 
      <tr> 
      <td width="23%" class="body"> Name</td> 
      <td width="3%" class="body">:</td> 
      <td width="74%"><input type="text" name="strname" class="textfield"></td> 
     </tr> 
     <tr><td style="height:3px"></td></tr> 
     <tr> 
      <td width="23%" class="body"> Address</td> 
      <td width="3%" class="body">:</td> 
      <td width="74%"><textarea cols="16" name="straddress"></textarea></td> 
     </tr> 
     <tr><td style="height:3px"></td></tr> 
     <tr> 
      <td width="23%" class="body"> City</td> 
      <td width="3%" class="body">:</td> 
      <td width="74%"><input type="text" name="strcity" class="textfield"></td> 
     </tr> 
     <tr><td style="height:3px"></td></tr> 
     <tr> 
      <td width="23%" class="body"> State</td> 
      <td width="3%" class="body">:</td> 
      <td width="74%"><input type="text" name="strstate" class="textfield"></td> 
     </tr> 
     <tr><td style="height:3px"></td></tr> 
     <tr> 
      <td width="23%" class="body"> Contact No</td> 
      <td width="3%" class="body">:</td> 
      <td width="74%"><input type="text" name="strno" class="textfield"></td> 
     </tr> 
     <tr><td style="height:3px"></td></tr> 
     <tr> 
      <td width="23%" class="body"> Email</td> 
      <td width="3%" class="body">:</td> 
      <td width="74%"><input type="text" name="stremail" class="textfield"></td> 
     </tr> 
     <tr><td style="height:3px"></td></tr> 
     <tr> 
      <td width="23%" class="body"> Comments</td> 
      <td width="3%" class="body">:</td> 
      <td width="74%"><textarea cols="16" name="strcomments"></textarea></td> 
     </tr> 
     <tr><td style="height:3px"></td></tr> 
     <tr> 
      <td width="23%" class="body"> Resume</td> 
      <td width="3%" class="body">:</td> 
      <td width="74%"><input type="file" name="strresume"></td> 
     </tr> 
     <tr><td style="height:10px"></td></tr> 
     <tr> 

     </tr> 

     </table> 
    </form> 

</td> 
    </tr> 
    <tr> 
     <td colspan="2" align="center"> </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 .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n"; 
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n"; 
$headers .= 'Cc: [email protected]' . "\r\n"; 
$headers .= 'Bcc: [email protected]' . "\r\n"; 

// Mail it 
mail($to, $subject, $message, $headers); 
?> 
+0

我不認爲所有的電子郵件客戶端都會接受您的電子郵件中的表單以發送發佈數據。 –

+0

那麼我是否正確?你希望在電子郵件的正文中添加一個表單?在這裏談論創新.. – dbf

+0

我想複製郵件正文中的選定表單數據。爲什麼會有問題? –

回答

0

我假設的形式從網站提交,你沒有嘗試創建電子郵件中的submittable形式。要複製表單中提交的數據,$ _POST [「」];肯定會是獲取數據的最佳方式。很明顯,一旦電子郵件到達收件人的收件箱,數據就不可操作,但正如我所說,我假設您並未嘗試創建可通過電子郵件提交的表單。

你的網站上的形式是罰款:然後

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 


<title>Untitled Document</title> 
</head> 

<body style="padding:3px; margin:0px;" bgcolor="#FFFFFF"> 
<table cellpadding="0" cellspacing="0" border="0" width="440"> 

<tr><td style="height:10px"></td></tr> 
<tr> 
    <td colspan="2" style="text-align:justify; line-height:15px;" class="body"> 

    <form name="frm" method="POST" action="careersuccess.php" enctype="multipart/form-data"> 
    <table cellpadding="0" cellspacing="0" border="0" width="100%"> 
     <tr> 
     <td width="23%" class="body"> Name</td> 
     <td width="3%" class="body">:</td> 
     <td width="74%"><input type="text" name="strname" class="textfield"></td> 
    </tr> 
    <tr><td style="height:3px"></td></tr> 
    <tr> 
     <td width="23%" class="body"> Address</td> 
     <td width="3%" class="body">:</td> 
     <td width="74%"><textarea cols="16" name="straddress"></textarea></td> 
    </tr> 
    <tr><td style="height:3px"></td></tr> 
    <tr> 
     <td width="23%" class="body"> City</td> 
     <td width="3%" class="body">:</td> 
     <td width="74%"><input type="text" name="strcity" class="textfield"></td> 
    </tr> 
    <tr><td style="height:3px"></td></tr> 
    <tr> 
     <td width="23%" class="body"> State</td> 
     <td width="3%" class="body">:</td> 
     <td width="74%"><input type="text" name="strstate" class="textfield"></td> 
    </tr> 
    <tr><td style="height:3px"></td></tr> 
    <tr> 
     <td width="23%" class="body"> Contact No</td> 
     <td width="3%" class="body">:</td> 
     <td width="74%"><input type="text" name="strno" class="textfield"></td> 
    </tr> 
    <tr><td style="height:3px"></td></tr> 
    <tr> 
     <td width="23%" class="body"> Email</td> 
     <td width="3%" class="body">:</td> 
     <td width="74%"><input type="text" name="stremail" class="textfield"></td> 
    </tr> 
    <tr><td style="height:3px"></td></tr> 
    <tr> 
     <td width="23%" class="body"> Comments</td> 
     <td width="3%" class="body">:</td> 
     <td width="74%"><textarea cols="16" name="strcomments"></textarea></td> 
    </tr> 
    <tr><td style="height:3px"></td></tr> 
    <tr> 
     <td width="23%" class="body"> Resume</td> 
     <td width="3%" class="body">:</td> 
     <td width="74%"><input type="file" name="strresume"></td> 
    </tr> 
    <tr><td style="height:10px"></td></tr> 
    <tr> 

    </tr> 

    </table> 
</form> 

</td> 
</tr> 
<tr> 
    <td colspan="2" align="center"> </td> 
</tr> 
</table> 
</body> 
</html> 

您的文件careersuccess.php需要包括像:

<?php 
// multiple recipients 
$to = '[email protected]' . ', '; // note the comma 
$to .= '[email protected]'; 

// subject 
$subject = 'Birthday Reminders for August'; 

$strName = $_POST["strname"]; //assigns strname from form to PHP variable 
$strAddress = $_POST["straddress"]; 
$strCity = $_POST["strcity"]; 
$strState = $_POST["strstate"]; 
$strNumber = $_POST["strnumber"]; 
$strEmail = $_POST["stremail"]; 
$strComments = $_POST["strcomments"]; 
$strResume = $_POST["strresume"]; 
$lineBreak = "<br />\n\"; //adds carriage return to break up your message 

$message = "Name: ".$strName.$lineBreak."Address: ".$strAddress.$lineBreak."City: ".$strCity.$lineBreak."State: ".$strState.$lineBreak...for the rest of your variables; 

// 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 .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n"; 
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n"; 
$headers .= 'Cc: [email protected]' . "\r\n"; 
$headers .= 'Bcc: [email protected]' . "\r\n"; 

// Mail it 
mail($to, $subject, $message, $headers); 
?> 

這將導致形式存在的提交值複製到mail()函數的$ message變量中的電子郵件中。