PHP mail()函数发送电子邮件

时间:2015-07-12 05:05:36

标签: html function email

以下是我在此页面上有一个名为contacts.html的页面的问题我有一个联系表单,其中包含以下代码

` <h2 class="top-1 p3">Contact form</h2>
        <form id="form" method="post"  action="html_form_send.php" >
          <fieldset>
            <label for="first_name"><strong>First Name:</strong><input type="text" name="first_name" value=""></label>
            <label for="last_name"><strong>Last Name:</strong><input type="text" name="last_name" value=""></label>
            <label for="email"><strong>Email:</strong><input type="text" name="email" value=""></label>
            <label for="telephone"><strong>Phone:</strong><input type="text" name="telephone" value=""></label>
            <label for="comments"><strong>Your Message:</strong><textarea></textarea></label>
<br>            <div class="btns"><a href="#" class="button">Clear</a><a href="#" class="button" onClick="document.getElementById('form').submit()">Send</a></div>`

这不是整个代码只是包含表单的部分。我使用GoDaddy来托管它并不支持X-mailer。我必须使用PHP的mail()函数。所以我一直在关注[http://php.net/manual/en/function.mail.php][1]。下面是我在html_form_send.php文件中的代码。表单发送这只是一个模板我不知道如何获取值(例如:first_name,last_name,comments)并将其写入php文件。我尝试将$ to = $ _POST [&#39; first_name&#39;];然后使用。$ data [&#39; first_name&#39;]但这不起作用。请丢弃随机表信息

$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 <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

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


  [1]: http://us2.php.net/manual/en/function.mail.php

谢谢!

0 个答案:

没有答案