我正在为我的wordpress主题构建一个联系表单。我希望能够从后端输入接收器地址。目前我正在使用隐藏的输入字段传递变量。
<input type="text" class="hidden" name="receiver" value="<?php get_option('admin_email') ?>"/>
我读到我不这样做,因为它不安全。但那我该怎么做呢?
编辑:这是我的process.php。我试图收到管理员电子邮件,但这会以某种方式打破它。
<?php if( isset($_POST) ){
//form validation vars
$formok = true;
$errors = array();
//sumbission data
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('d.m.Y');
$time = date('H:i');
//form data
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$budget = $_POST['budget'];
$message = $_POST['message'];
$receiver = $_POST['receiver'];
$sender = get_option('admin_email');
if(empty($name)){
$formok = false;
$errors[] = "Sie haben keinen Namen angegeben.";
}
if(empty($email)){
$formok = false;
$errors[] = "Sie haben keine Emailadresse angegeben.";
//validate email address
}elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$formok = false;
$errors[] = "Sie haben keine gültige Emailadresse angegeben.";
}
if(empty($message)){
$formok = false;
$errors[] = "Das Nachrichtenfeld ist leer.";
}
elseif(strlen($message) < 20){
$formok = false;
$errors[] = "Ihre Nachricht muss mindestens 20 Zeichen enthalten.";
}
if($formok){
$headers = "From: {$email}" . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$emailbody = "<p><strong>Name: </strong> {$name} </p>
<p><strong>Website: </strong> {$website} </p>
<p><strong>Nachricht: </strong> {$message} </p>
<p>Diese Nachricht wurde am {$date} um {$time} über {$sender} gesendet.</p>";
if($receiver){
mail($receiver,"Anfrage ".$name,$emailbody,$headers);
}
else{
mail('test@test.com',"Error",$emailbody,$headers);
}
}
//what we need to return back to our form
$returndata = array(
'posted_form_data' => array(
'name' => $name,
'email' => $email,
'website' => $website,
'budget' => $budget,
'message' => $message
),
'form_ok' => $formok,
'errors' => $errors
);
//if this is not an ajax request
if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest'){
//set session variables
session_start();
$_SESSION['cf_returndata'] = $returndata;
//redirect back to form
header('location: ' . $_SERVER['HTTP_REFERER']);
}
}
答案 0 :(得分:3)
由于你知道接收者地址 - 你不应该通过它。 提交表单时 - 您可以使用后端PHP脚本发送它,而不会将其暴露给用户!
答案 1 :(得分:2)
使用会话。当用户提交时,将数据发送到将解析所有数据的以下SQL查询
答案 2 :(得分:0)
将表单处理代码放在Wordpress页面模板中,然后您可以在后端表单代码中使用get_option('admin_email')
,而不必在公共网页上公开它。