0

我正在尝试编写表单/工作申请,但不能完全决定如何发送它。我已经知道如何通过电子邮件发送所有信息。

我想做的是通过电子邮件发送信息,但我希望电子邮件显示 html 编码以更好地组织数据。我在 PHP 中声明了所有内容,我只是在决定消息:

<?php

$to = "jobs@enhstudios.com";
$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);

?>

我想在 $message 中写一个表格,并将数据显示在一个漂亮的整洁表格中。

4

3 回答 3

0

是的,建立一个 HTML 表格,然后进行$headers适当的设置(参见示例 #4:http: //php.net/manual/en/function.mail.php)。

于 2013-05-28T19:58:09.253 回答
0

下面是我对 PHP 后端的全部编码。我确实收到了电子邮件...但是,它全部在 HTML 代码中,并且没有提取任何信息

<?php

$to = "jobs@enhstudios.com";
$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>
于 2013-06-13T16:13:21.827 回答
-1

要发送 HTML 邮件,必须设置 Content-type 标头

$headers = 'MIME 版本:1.0' 。"\r\n";

$headers .= '内容类型:文本/html;字符集=iso-8859-1' 。"\r\n";

 //Here is a example how to use   


<?php
        // to email
        $to  = 'test@example.com';

        // 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 <test@example.com>' . "\r\n";
        $headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";


        // Mail it
        if(mail($to, $subject, $message, $headers))
          {
           echo "mail sent sucessfully";
          }
         else
          {
           echo "Unable to send mail";
          }
?>
于 2013-05-28T20:11:40.210 回答