gpt4 book ai didi

PHP根据表单名称发布给不同的用户

转载 作者:行者123 更新时间:2023-11-28 03:15:36 24 4
gpt4 key购买 nike

尝试找出最佳方法让下面的 PHP 根据它来自的表单名称发布到不同的用户电子邮件地址。

例如。此表格是 name="engineering-australia",我还有其他名字不同的表格。我希望这个转到 user1@domain.com,另一个转到 user2@domain.com 等等。

我的问题是,执行此操作的最佳方法是什么,我不想使用 javascript - 我在考虑某种 if 语句?但是不需要以某种方式提取表单名称吗?

另外值得一提的是,除了表单名称之外,表单是相同的,我不想为每个表单创建不同的 PHP 脚本。

HTML

<form class="form-contact" name="engineering-australia">
<fieldset>
<input id="form-name" name="name" type="text" placeholder="Your Name" />
<input id="form-email" name="email" type="text" placeholder="Your Email" />
</fieldset>
<textarea id="form-msg" name="message" rows="10" placeholder="Your Message" ></textarea>
<input type="submit" name="submit" class="button button-small" value="Send Message" />
</form>

PHP

<?php

define('kOptional', true);
define('kMandatory', false);

error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);

function DoStripSlashes($fieldValue) {
// temporary fix for PHP6 compatibility - magic quotes deprecated in PHP6
if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
if (is_array($fieldValue) ) {
return array_map('DoStripSlashes', $fieldValue);
} else {
return trim(stripslashes($fieldValue));
}
} else {
return $fieldValue;
}
}

function FilterCChars($theString) {
return preg_replace('/[\x00-\x1F]/', '', $theString);
}

function CheckEmail($email, $optional) {
if ( (strlen($email) == 0) && ($optional === kOptional) ) {
return true;
} elseif ( preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $email) == 1 ) {
return true;
} else {
return false;
}
}

if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}

$FTGname = DoStripSlashes( $_POST['name'] );
$FTGemail = DoStripSlashes( $_POST['email'] );
$FTGmessage = DoStripSlashes( $_POST['message'] );
$FTGsubmit = DoStripSlashes( $_POST['submit'] );

$validationFailed = false;

# Fields Validations

if (!CheckEmail($FTGemail, kMandatory)) {
$FTGErrorMessage['email'] = 'ERROR MESSAGE';
$validationFailed = true;
}

# Redirect user to error message

if ($validationFailed === true) {

header("Location: index.php?success=2");

}

if ( $validationFailed === false ) {

# Email to Form Owner

$emailSubject = FilterCChars("Website Enquiry");

$emailBody = chunk_split( base64_encode( "<html>\n"
. "<head>\n"
. "<title></title>\n"
. "</head>\n"
. "<body>\n"
. "Name : $FTGname<br />\n"
. "Email : $FTGemail<br />\n"
. "Message : " . nl2br( $FTGmessage ) . "\n"
. "</body>\n"
. "</html>" ) )
. "\n";
$emailTo = 'User <user1@domain.com>';

$emailFrom = FilterCChars("$FTGemail");

$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-Type: text/html; charset=\"UTF-8\"\n"
. "Content-Transfer-Encoding: base64\n"
. "\n";

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

# Redirect user to success message

header("Location: index.php?success=1");

}

?>

最佳答案

您不会在 PHP 中获取表单名称。尝试在每种形式中使用隐藏输入:

<input name="form" type="hidden" value="engineering-australia" />

然后在 PHP 中检查 $_POST['form']

switch($_POST['form']) {
case 'engineering-australia':
$email = 'user1@domain.com';
break;
case 'something-else':
$email = 'user2@domain.com';
break;
}

关于PHP根据表单名称发布给不同的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28131799/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com