2013-05-28 144 views
0

我正在嘗試寫一個表單/工作應用程序,並不能完全決定如何發送它。我已經知道如何通過電子郵件發送所有信息。試圖通過HTML電子郵件發送PHP表單數據

我想要做的是通過電子郵件發送信息,但我希望電子郵件顯示html編碼以更好地組織數據。我把一切都宣告PHP我只是決定消息:

<?php 

$to = "[email protected]"; 
$fname = $_POST['fname']; 
$lname = $_POST['lname']; 
$age = $_POST['age']; 
$address = $_POST['address']; 
$aptno = $_POST['aptno']; 
$city = $_POST['city']; 
$state = $_POST['state']; 
$zip = $_POST['zip']; 
$phone = $_POST['phone']; 
$phonetype = $_POST['phonetype']; 
$jdate1 = $_POST['jdate1']; 
$employer1 = $_POST['employer1']; 
$title1 = $_POST['title1']; 
$leaving1 = $_POST['leaving1']; 
$jdate2 = $_POST['jdate2']; 
$employer2 = $_POST['employer2']; 
$title2 = $_POST['title2']; 
$leaving2 = $_POST['leaving2']; 
$jdate3 = $_POST['jdate3']; 
$employer3 = $_POST['employer3']; 
$title3 = $_POST['title3']; 
$leaving3 = $_POST['leaving3']; 
$skills = $_POST['skills']; 
$subject = $fname." ".$lname."Application"; 
$message = 
$from = $email; 
mail($to,$subject,$message); 

?> 

我想在$消息表寫入和擁有的數據在一個不錯的整齊的表格顯示出來。

+1

您的問題是什麼? – Ryan

+0

我想這個問題是: 當在$ message中寫入HTML代碼時,我只是編碼一個表嗎? –

+0

您可以使用變量$ message在表格中存儲包含PHP變量的HTML表格。如果你選擇循環查詢的結果,你可以使用$ message。='';讓你的生活更輕鬆。 – Ryan

回答

-1

要發送HTML郵件時,Content-type頭必須設置

$標題= 'MIME-版本:1.0'。爲 「\ r \ n」 個;

$ headers。='Content-type:text/html; charset = iso-8859-1'。爲 「\ r \ n」 個;

//Here is a example how to use 


<?php 
     // to email 
     $to = '[email protected]'; 

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

     // message 
     $message = ' 
     <html> 
     <head> 
      <title>Birthday Reminders for August</title> 
     </head> 
     <body> 
      <p>Here are the birthdays upcoming in August!</p> 
      <table> 
      <tr> 
       <th>Person</th><th>Day</th><th>Month</th><th>Year</th> 
      </tr> 
      <tr> 
       <td>Joe</td><td>3rd</td><td>August</td><td>1970</td> 
      </tr> 
      <tr> 
       <td>Sally</td><td>17th</td><td>August</td><td>1973</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]>' . "\r\n"; 
     $headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n"; 


     // Mail it 
     if(mail($to, $subject, $message, $headers)) 
      { 
      echo "mail sent sucessfully"; 
      } 
     else 
      { 
      echo "Unable to send mail"; 
      } 
?> 
+0

這促成了弊端,並且由於缺少純文本版本並試圖欺騙「發件人」標題而被大多數垃圾郵件過濾器捕獲。 –

+0

這封電子郵件將直接發送給我,並且我的垃圾郵件過濾器已設置爲允許此操作。我已經嘗試過兩種方式,並且電子郵件已發送,但是我只收到代碼。 –

+0

@Nathan Stotts您是否將腳本與腳本中的腳本連接起來? – sAnS

0

以下是我對PHP背面的完整編碼。我確實收到了電子郵件...但是,這些都在HTML代碼中,並且沒有提供任何信息

<?php 

$to = "[email protected]"; 
$email = $_POST['email']; 
$fname = $_POST['fname']; 
$lname = $_POST['lname']; 
$age = $_POST['age']; 
$address = $_POST['address']; 
$aptno = $_POST['aptno']; 
$city = $_POST['city']; 
$state = $_POST['state']; 
$zip = $_POST['zip']; 
$phone = $_POST['phone']; 
$phonetype = $_POST['phonetype']; 
$jobtype1 = $_POST['jobtype1']; 
$jobtype2 = $_POST['jobtype2']; 
$jdate1 = $_POST['jdate1']; 
$edate1 = $_POSt['edate1']; 
$employer1 = $_POST['employer1']; 
$title1 = $_POST['title1']; 
$leaving1 = $_POST['leaving1']; 
$jdate2 = $_POST['jdate2']; 
$edate2 = $_POSt['edate2']; 
$employer2 = $_POST['employer2']; 
$title2 = $_POST['title2']; 
$leaving2 = $_POST['leaving2']; 
$jdate3 = $_POST['jdate3']; 
$edate3 = $_POSt['edate3']; 
$employer3 = $_POST['employer3']; 
$title3 = $_POST['title3']; 
$leaving3 = $_POST['leaving3']; 
$skills = $_POST['skills']; 
$subject = $fname." ".$lname. " Application"; 
$message = 
'<html> 
<head> 
</head> 
<body> 
<table border="2" cellpadding="4" cellspacing="3"> 
<tr> 
<th colspan="5">Personal Information:</th> 
</tr> 
<tr> 
<td colspan="2">First Name:</td> 
<td colspan="2">Last Name:</td> 
<td>Age:</td> 
</tr> 
<tr> 
<td colspan="2"> 
    <?php echo $_POST["fname"]; ?> 
</td> 
<td colspan="2"> 
    <?php echo $_POST["lname"]; ?> 
</td> 
<td> 
    <?php echo $_POST["age"]; ?> 
</td> 
</tr> 
<tr> 
<td>Street:</td> 
<td>Apt/Suite</td> 
<td>City:</td> 
<td>State:</td> 
<td>Zip Code:</td> 
</tr> 
<tr> 
<td> 
    <?php echo $_POST["address"]; ?> 
</td> 
<td> 
    <?php echo $_POST["aptno"]; ?> 
</td> 
<td> 
    <?php echo $_POST["city"]; ?> 
</td> 
<td> 
    <?php echo $_POST["state"]; ?> 
</td> 
<td> 
    <?php echo $_POST["zip"]; ?> 
</td> 
</tr> 
<tr> 
<td colspan="2">Phone Number:</td> 
<td>Phone Type:</td> 
<td></td> 
<td></td> 
<tr> 
<td colspan="2"> 
    <?php echo $_POST["phone"]; ?> 
</td> 
<td> 
    <?php echo $_POST["phonetype"]; ?> 
</td> 
<td> 
</td> 
<td> 
</td> 
</tr> 
<tr> 
<td colspan="2">Please select job(s) you are applying for:</td> 
<td></td> 
<td></td> 
<td></td> 
<tr> 
    <td> 
      <?php echo $_POST["jobtype1"]; ?> 
    </td> 
    <td> 
      <?php echo $_POST["jobtype2"]; ?> 
    </td> 
    <td> 
    </td> 
    <td> 
    </td> 
    <td> 
    </td> 
</tr> 
<tr> 
<th colspan="5">Employment History:</th> 
</tr> 
<tr> 
<td>Month/Year Start:</td> 
<td>Month/Year End:</td> 
<td>Employer:</td> 
<td>Title/Position:</td> 
<td>Reason For Leaving:</td> 
</tr> 
<tr> 
<td> 
    <?php echo $_POST["jdate1"]; ?> 
</td> 
<td> 
    <?php echo $_POST["edate1"]; ?> 
</td> 
<td> 
    <?php echo $_POST["employer1"]; ?> 
</td> 
<td> 
    <?php echo $_POST["title1"]; ?> 
</td> 
<td> 
    <?php echo $_POST["leaving1"]; ?> 
</td> 
</tr> 
<tr> 
<td> 
    <?php echo $_POST["jdate2"]; ?> 
</td> 
<td> 
    <?php echo $_POST["edate2"]; ?> 
</td> 
<td> 
    <?php echo $_POST["employer2"]; ?> 
</td> 
<td> 
    <?php echo $_POST["title2"]; ?> 
</td> 
<td> 
    <?php echo $_POST["leaving2"]; ?> 
</td> 
</tr> 
<tr> 
<td> 
    <?php echo $_POST["jdate3"]; ?> 
</td> 
<td> 
    <?php echo $_POST["edate3"]; ?> 
</td> 
<td> 
    <?php echo $_POST["employer3"]; ?> 
</td> 
<td> 
    <?php echo $_POST["title3"]; ?> 
</td> 
<td> 
    <?php echo $_POST["leaving3"]; ?> 
</td> 
</tr> 
<tr> 
<th colspan="5">Special Skills:</th> 
</tr> 
<tr> 
<td colspan="5"> 
    <?php echo $_POST["skills"]; ?> 
</td> 
</tr> 
</table> 
</body> 
</html>'; 
$from = $email; 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers = "From:" . $from; 
mail($to,$subject,$message,$headers); 

?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http:www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>ENH Studios</title> 
<link rel="stylesheet" type="text/css" href="careerstyle.css" media="screen" /> 
</head> 
<body> 
<div id="header"> 
<div id="logo"> 
</div> 

<div id="intro"> 

    <p><?php echo $_POST["fname"]; ?>&nbsp<?php echo $_POST["lname"]; ?>'s Application</p> 
</div> 
</div> 
<div id="content"> 
<p>Thank you for your interest in working with ENH Studios, we will review your application and contact you to set up an interview</p> 
<p>We interview EVERYONE who applies with us</p> 
<table border="2" cellpadding="4" cellspacing="3"> 
<tr> 
<th colspan="5">Personal Information:</th> 
</tr> 
<tr> 
<td colspan="2">First Name:</td> 
<td colspan="2">Last Name:</td> 
<td>Age:</td> 
</tr> 
<tr> 
<td colspan="2"> 
    <?php echo $_POST["fname"]; ?> 
</td> 
<td colspan="2"> 
    <?php echo $_POST["lname"]; ?> 
</td> 
<td> 
    <?php echo $_POST["age"]; ?> 
</td> 
</tr> 
<tr> 
<td>Street:</td> 
<td>Apt/Suite</td> 
<td>City:</td> 
<td>State:</td> 
<td>Zip Code:</td> 
</tr> 
<tr> 
<td> 
    <?php echo $_POST["address"]; ?> 
</td> 
<td> 
    <?php echo $_POST["aptno"]; ?> 
</td> 
<td> 
    <?php echo $_POST["city"]; ?> 
</td> 
<td> 
    <?php echo $_POST["state"]; ?> 
</td> 
<td> 
    <?php echo $_POST["zip"]; ?> 
</td> 
</tr> 
<tr> 
<td colspan="2">Phone Number:</td> 
<td>Phone Type:</td> 
<td></td> 
<td></td> 
<tr> 
<td colspan="2"> 
    <?php echo $_POST["phone"]; ?> 
</td> 
<td> 
    <?php echo $_POST["phonetype"]; ?> 
</td> 
<td> 
</td> 
<td> 
</td> 
</tr> 
<tr> 
<td colspan="2">Please select job(s) you are applying for:</td> 
<td></td> 
<td></td> 
<td></td> 
<tr> 
    <td> 
      <?php echo $_POST["jobtype1"]; ?> 
    </td> 
    <td> 
      <?php echo $_POST["jobtype2"]; ?> 
    </td> 
    <td> 
    </td> 
    <td> 
    </td> 
    <td> 
    </td> 
</tr> 
<tr> 
<th colspan="5">Employment History:</th> 
</tr> 
<tr> 
<td>Month/Year Start:</td> 
<td>Month/Year End:</td> 
<td>Employer:</td> 
<td>Title/Position:</td> 
<td>Reason For Leaving:</td> 
</tr> 
<tr> 
<td> 
    <?php echo $_POST["jdate1"]; ?> 
</td> 
<td> 
    <?php echo $_POST["edate1"]; ?> 
</td> 
<td> 
    <?php echo $_POST["employer1"]; ?> 
</td> 
<td> 
    <?php echo $_POST["title1"]; ?> 
</td> 
<td> 
    <?php echo $_POST["leaving1"]; ?> 
</td> 
</tr> 
<tr> 
<td> 
    <?php echo $_POST["jdate2"]; ?> 
</td> 
<td> 
    <?php echo $_POST["edate2"]; ?> 
</td> 
<td> 
    <?php echo $_POST["employer2"]; ?> 
</td> 
<td> 
    <?php echo $_POST["title2"]; ?> 
</td> 
<td> 
    <?php echo $_POST["leaving2"]; ?> 
</td> 
</tr> 
<tr> 
<td> 
    <?php echo $_POST["jdate3"]; ?> 
</td> 
<td> 
    <?php echo $_POST["edate3"]; ?> 
</td> 
<td> 
    <?php echo $_POST["employer3"]; ?> 
</td> 
<td> 
    <?php echo $_POST["title3"]; ?> 
</td> 
<td> 
    <?php echo $_POST["leaving3"]; ?> 
</td> 
</tr> 
<tr> 
<th colspan="5">Special Skills:</th> 
</tr> 
<tr> 
<td colspan="5"> 
    <?php echo $_POST["skills"]; ?> 
</td> 
</tr> 
</table> 
</body> 
</html> 
相關問題