我正在使用来自其他来源的代码,但它与使用标准HTML / PHP网站时我习惯编码的方式非常不同。 Wordpress似乎有自己的想法。基本上我需要联系表格的PHP在电子邮件的正文中发送姓名和电子邮件,而不仅仅是个人消息。目前所有这些都是人物信息。
<?php
//response generation function
$response = "";
//function to generate response
function my_contact_form_generate_response($type, $message){
global $response;
if($type == "success") $response = "<div class='success'>{$message}</div>";
else $response = "<div class='error'>{$message}</div>";
}
//response messages
$not_human = "Human verification incorrect.";
$missing_content = "Please Fill in all Required Fields.";
$email_invalid = "Your Email Address is Invalid.";
$message_unsent = "Message was not sent. Please Try Again.";
$message_sent = "Thanks! Your message has been sent.";
//user posted variables
$name = $_POST['message_name'];
$email = $_POST['message_email'];
$message = $_POST['message_text'];
$human = $_POST['message_human'];
//php mailer variables
$to = get_option('admin_email');
$subject = "New Enquiry Through Mon Voyage Website";
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
if(!$human == 0){
if($human != 2) my_contact_form_generate_response("error", $not_human); //not human!
else {
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
my_contact_form_generate_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($message)){
my_contact_form_generate_response("error", $missing_content);
}
else //ready to go!
{
$sent = wp_mail($to, $subject, strip_tags($message), $headers);
if($sent) my_contact_form_generate_response("success", $message_sent); //message sent!
else my_contact_form_generate_response("error", $message_unsent); //message wasn't sent
}
}
}
}
else if ($_POST['submitted']) my_contact_form_generate_response("error", $missing_content);
?>
有什么想法吗?
答案 0 :(得分:0)
在if(!$ human == 0){:
之前添加$message.='Name: '.$name.'email: '$email;
这是所有标准的PHP表格检查,1。显示响应的功能2.检查$ _POST数据3.如果错误到位则失败4.如果没有错误,发送电子邮件。在那里放几个回声并玩弄它看看发生了什么。
答案 1 :(得分:0)