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>';
?>
表單的人選擇看起來很不錯(假設你在這些選項中使用實際的電子郵件地址值),但你的'$主題'從哪裏來? –
你配置了你的php.ini來發送郵件嗎?這裏是一個教程,概述你需要做的事情:https://www.quackit.com/php/tutorial/php_mail_configuration.cfm – user1760150
@nathan檢查下面的郵件代碼,郵件(「[email protected] 「,」我的主題「,」WORKS!「); – ben