wordpress订餐接受表单

<?php
/**
* 联系页面, 邮件发送.
*/

//只可以用post方法
if ($_SERVER["REQUEST_METHOD"] != "POST") {
header('Allow: POST');
header("HTTP/1.1 405 Method Not Allowed");
header("Content-type: text/plain");
exit;
}

// Sets up the WordPress Environment
require_once(preg_replace( '/wp-content.*/', '', __FILE__ ).'wp-load.php');

require_once ABSPATH . WPINC . '/class-phpmailer.php';
require_once ABSPATH . WPINC . '/class-smtp.php';
$phpmailer = new PHPMailer();

session_start();

$adminEmail = get_option('admin_email');

if(!$adminEmail){
fail(__('Admin\'s E_mail address is empty!', YHL));
}

// get post data
$name = isset($_POST['name']) ? trim($_POST['name']) : null;
$from = isset($_POST['from']) ? trim($_POST['from']) : null;
$subject = isset($_POST['subject']) ? trim($_POST['subject']) : null;
$vcode = isset($_POST['vcode']) ? trim($_POST['vcode']) : null;
$content = isset($_POST['content']) ? stripslashes(trim($_POST['content'])) : null;
$computer = isset($_POST['computer']) ? stripslashes(trim($_POST['computer'])) : null;
$tel = isset($_POST['tel']) ? stripslashes(trim($_POST['tel'])) : null;
$biaozhun = isset($_POST['biaozhun']) ? stripslashes(trim($_POST['biaozhun'])) : null;
$address = isset($_POST['address']) ? stripslashes(trim($_POST['address'])) : null;

// check post data
if(!$name||!$computer||!$tel||!$biaozhun||!$address){
wp_die(__('错误: 请填写必填项目 (姓名, 单位名称, 联系电话,用餐标准,地址)'));
}

if($_SESSION['vcode'] !== $vcode) {
wp_die(__('验证码错误'));
}

if(!$content){
wp_die(__('请输入备注'));
}

$title = "新订单(标准:.".$biaozhun."):".$name."(".$tel.")";
$receive = "83364664@qq.com";//此处为接受邮箱
$content = '
<div style="background-color:#eef2fa; border:1px solid #d8e3e8; color:#111; padding:0 15px; -moz-border-radius:5px; -webkit-border-radius:5px; -khtml-border-radius:5px;">
<p>您好!最新订单</p>
<p>订餐信息如下:<br /></p>
<p>姓名:'.$name.',单位名称:'.$computer.',联系电话:'.$tel.'<br />
地址:'.$address.',备注:'.$content.'<br /></p>
<p>用餐标准:'.$biaozhun.'</p>
<p>来自:<a href="' . get_option('home') . '">' . get_option('blogname') . '</a></p>
</div>';

$headers = "\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
// do send
$result = wp_mail($receive,$title,$content,$headers);

unset($_POST['vcode']);

if($result){
$response = sprintf(__('恭喜你, %1$s. 订单已生成. 我将尽快回复你!'),$name);
if(defined('DOING_AJAX')){
echo '<p>', $response, '</p>';
}else{
wp_die($response, __('邮件发送成功'));
}
}else{
wp_die(__('出错了! 很抱歉. 你可以尝试其他方式联系我.'));
}

?>

分享