-1

嘿,我想创建一个具有下拉菜单的联系表格,根据您选择的 3 个选项中的哪一个,表格将被发送到不同的电子邮件。我不知道这是否可能,但任何帮助将不胜感激

<form action="process.php" method="post" id="contact_form">
    <p class="contact-form-sender">
    <input id="name" type="text" placeholder="Name" name="name" />
    </p>
    <p class="contact-form-email">
    <input id="email" type="text" placeholder="Email" name="email" />
    </p>
    <p class="contact-form-subject">
    <input id="subject" type="text" placeholder="Subject" name="subject" />
    </p>

    <p class="contact-form-content">
    <textarea id="message" placeholder="Your enquiries" name="message"></textarea>
    </p>

    <span class="button-met light"><input id="consubmit" type="submit" name="consubmit" value="Send" /></span>
</form>
<?php 
$toemail = 'email@gmail.com';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
if(mail($toemail, $subject , $message, 'From: ' . $email)) {
    echo 'Your email was sent successfully.';
} else {
    echo 'There was a problem sending your email.';
}
?>

是我用于表单的代码

4

1 回答 1

0

注意你在哪里使用表单值:

$name = $_POST['name'];

在您不使用表单值的地方:

$toemail = 'email@gmail.com';

为了通过表单元素使“收件人”地址动态化,只需为其添加一个表单元素并使用它来代替硬编码的电子邮件地址。因此,您可以select在表单中添加一个,如下所示:

<select name="toAddress">
    <option value="email1@address.com">email1@address.com</option>
    <option value="email2@address.com">email2@address.com</option>
    <option value="email3@address.com">email3@address.com</option>
</select>

(当然,您会希望使用有问题的实际电子邮件地址。)

然后在您的代码中,您将使用表单值:

$toemail = $_POST['toAddress'];
于 2013-07-16T23:43:38.870 回答