在提交时将表单发送到一个电子邮件,但在不同的提交时发送到不同的电子邮件?

Send a Form to one email on submit but to a different email on a different submission?

我对此还是有点陌生​​,不知道从哪里开始。 我想创建一个 php 联系表格,其中填写表格并提交的 user_1 发送至 Emai_1,填写表格的 user_2 发送至 Email_2 所以它在两者之间继续。还是不可能?

您想交替向两个不同的电子邮件 ID 发送邮件,因此要实现这一点,您需要在数据库中存储一个变量,该变量将在每次提交后保存 last_email_sent_to 的值。并且每次您将使用其他值发送电子邮件并将其更新为 "last_email_sent_to" 变量。

希望对您有所帮助。

您的提交按钮:

<input type="submit" name="sales_submit" value="Contact sales department" />
<input type="submit" name="hr_submit" value="Contact HR department" />

在操作页面上,您的 PHP 脚本:

<?php
if(!empty($_POST['sales_submit'])) {
    //send email to Robert
} elseif(!empty($_POST['hr_submit'])) {
    // send email to Sabrina
} else {
    // How the hell did you reach this code without any submit button?
}

如果电子邮件目的地取决于表单值,您可以使用相同的技术。您可以在表单登陆页面上的 PHP 代码中测试值并更改行为,而不是使用两个提交按钮。提交按钮与其他输入具有完全相同的行为

<?php
if(!empty($_POST['question_is_sales_relative'])) {
// do an action for sales
} else {
// ...
}