如何在php邮件中包含标题?

时间:2016-06-05 10:16:10

标签: php email

每当用户点击发送按钮时,我都会尝试从联系表单发送一封小电子邮件。我坚持的是标题中的from选项。我不确定如何在邮件中包含“发件人”电子邮件ID /如何包含发件人电子邮件。这是我的代码:

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">  

<table id ="contact_us" cellpadding="5px">

 <tr>
 <td>Name : </td>
 <td><input style="border-radius: 5px; width: 200px; height: 20px;" type="text" id="name" name="name" required/></td>
 </tr>
 <tr>
 <td>Email : </td>
<td><input style="border-radius: 5px; width: 200px; height: 20px;" type="email" id="email" name="email" required/></td>
</tr>
<tr>
<td>Comments : </td>
<td><textarea style="border-radius: 5px;" cols = "40" rows="5" id="query" name="query" required></textarea></td>
</tr>

<tr>
<td><input style="border-radius: 5px; width: 80px; height:25px;" type="submit" id="submit" name="submit" value="Send"></td>
</tr>

</table>
</form> 



 <?php

    if(isset($_POST['submit']) && $_POST['submit'] == 'Send') {
       $mailerName = $_POST['name'];
       $emailer = $_POST['email'];
       $comments = $_POST['query'];


       function sendEmail(){
       $to = "email@domain.com";
       $subject = "emailQuery";
       $message = $comments;
       $headers = 'From: '.$mailerName;.'' . "\r\n" .'Reply-To: webmaster@example.com' . "\r\n" .'X-Mailer: PHP/' . phpversion();

      $headers = 'From: '.$mailerName;

      mail($to, $subject, $message, $headers);
                }
      sendEmail();

      echo '
            <div id="emailSent_message" style="border-radius: 2px; border-top: 2px solid gray; padding: 20px;">
            Your email is sent to us and will be responded to as soon as possible. Thankyou for your message!!
            </div>
            ';
            }

  ?>

0 个答案:

没有答案