2017-10-06 53 views
0

我知道這已被問過,但我不明白給出的答案和/或無法找到一種方法,使其爲我自己工作。我只是希望將我的聯繫表單中的郵件發送給在表單頁面上的下拉選擇中選擇的人員。聯繫表發送到選定的電子郵件從下拉列表

注意:我對此很新。

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>'; 
?> 
+2

表單的人選擇看起來很不錯(假設你在這些選項中使用實際的電子郵件地址值),但你的'$主題'從哪裏來? –

+0

你配置了你的php.ini來發送郵件嗎?這裏是一個教程,概述你需要做的事情:https://www.quackit.com/php/tutorial/php_mail_configuration.cfm – user1760150

+0

@nathan檢查下面的郵件代碼,郵件(「[email protected] 「,」我的主題「,」WORKS!「); – ben

回答

0
$headers = "Reply-To: <[email protected]>\r\n"; 
    $headers .= "Return-Path: Team <[email protected]>\r\n"; 
    $headers .= "From: Team <[email protected]>\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); 

而不是僅僅從傳遞標頭信息希望這有助於通過$

+0

我不知道這是如何解決我的問題,雖然?我只需要表單數據通過電子郵件發送給表單上的選定人員... –

相關問題