I have a form whose message is composed from multiple input fields when submitted. I got this form working as simple php document but when I'm trying to use the form within a wordpress page it doesn't work. And I've switched to wp_mail function. Anyone has any idea? Thank you
<?php
$errors = array();
$missing = array();
if (isset($_POST['send'])) {
$to = '[email protected]';
$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 protected]>\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;
}
}
?>
get_header
in the page's template?if
block? The$mailSent
is not set there and you are trying to redirect? Also why you are checking for array hereif (is_array($val))
?