联系表单从下拉列表发送到选定的电子邮件

时间:2017-10-06 03:09:15

标签: php forms

我知道之前已经问过这个问题,但是我不理解给出的答案和/或找不到让自己有效的方法。我只是希望将联系表单中的消息发送给表单页面下拉选项中选择的任何人。

注意:我对此很新。

HTML

  <form method="post" action="contact.php">
        <br>
           <input name="name" type="text" maxlength="35" autocomplete="off" minlength="1" placeholder="Name" required/>
        <br>
           <select name="to" placeholder="Select One" required>
              <option value="Select One" disabled selected> --- Send to --- </option>
              <option value="p1">person 1</option>
              <option value="p2">person 2</option>
              <option value="p3">person 3</option>
           </select>
        <br>
           <input name="email" type="email" maxlength="35" autocomplete="off" minlength="1" placeholder="Email" required/>
        <br>
           <textarea name="message" maxlength="350" minlength="20" placeholder="Message" required></textarea>
        <br>
     <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
        <br>
  </form>

PHP

<?php
$from = $_POST["name"];
$to = $_POST["to"];
$email_from = $_POST["email"];
$message = $_POST["message"];

$subject = "New message from" . $from;

mail($to,$subject,$message,$email_from);

echo '<br><center><p>Your message has been sent.</center>';
?>

1 个答案:

答案 0 :(得分:0)

    $headers = "Reply-To:  <info@xyz.com>\r\n"; 
    $headers .= "Return-Path: Team <info@xyz.com>\r\n"; 
    $headers .= "From: Team <info@xyz.com>\r\n"; 
    $headers .= "Organization: Team\r\n";
    $headers .= "MIME-Version: 1.0\r\n";                                
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= "X-Priority: 1\r\n";
    $headers .= "X-Mailer: PHP". phpversion() ."\r\n"; 

    $sent = mail( $to,$email_subject,$message,$headers);

而不仅仅是传递$来自标题中的信息希望这有助于