我有一个表单,它的消息在提交时由多个输入字段组成。我将此表单作为简单的php文档使用,但当我尝试在wordpress页面中使用此表单时,它不起作用。我已经切换到wp\\u邮件功能。有人知道吗?非常感谢。
<?php
$errors = array();
$missing = array();
if (isset($_POST[\'send\'])) {
$to = \'mail@yahoo.com\';
$subject = \'Form\';
$expected = array(\'name\', \'email\', \'pick_up_adress\', \'drop_off_adress\', \'phone\', \'pick_date\', \'pick_time\', \'type\');
$required = array(\'name\', \'email\', \'pick_up_adress\', \'drop_off_adress\', \'phone\', \'pick_date\', \'pick_time\', \'type\');
$headers = "From: Metro<email@example.com>\\r\\n";
$headers .= \'Content-Type: text/plain; charset=utf-8\';
if ($mailSent) {
header(\'Location: after_form.php\');
exit;
}
}
// Array proccesing
$mailSent = false;
if (!$suspect && !$missing && !$errors) {
$message = \'\';
foreach($expected as $item) {
if (isset(${$item}) && !empty(${$item})) {
$val = ${$item};
} else {
$val = \'Not selected\';
}
if (is_array($val)) {
$val = implode(\', \', $val);
}
$item = str_replace(array(\'_\', \'-\'), \' \', $item);
$message .= ucfirst($item).": $val\\r\\n\\r\\n";
}
$message = wordwrap($message, 70);
// simple php doc $mailSent = mail($to, $subject, $message, $headers);
$mailSent = wp_mail($to, $subject, $message, $headers);
if (!$mailSent) {
$errors[\'mailfail\'] = true;
}
}
?>