I've created a contact form using PHP mail() directly inside a page. It successfully emails te contact information to the recipient. However, it won't advance to the confirmation page identified in header() and outputs the following error:
Warning: Cannot modify header information - headers already sent by (output started at /home/redacted/redacted.com/wp-content/themes/diner/includes/theme-functions.php:752) in /home/redacted/redacted.com/wp-content/themes/diner/page.php on line 163
Any advice or resource links on how to fix this?
<?php
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_REQUEST['contact_email']))
{//if "email" is filled out, proceed
//check if the email address is invalid
$mailcheck = spamcheck($_REQUEST['contact_email']);
if ($mailcheck==FALSE)
{
echo "Invalid input";
}
else
{//send email
$inquirer_name = $_REQUEST['contact_name'] ;
$email = $_REQUEST['contact_email'] ;
wp_mail(
"[email protected]",
"Subject: Test contact",
"Name: $inquirer_name
Email: $email "
);
header("Location:http://redacted.com/contact-confirmed");
}
} else { //if "email" is not filled out, display the form ?>
<form method="post" action="http://redacted.com/contact">
<ul>
<li>First Name: <input name="contact_name" type="text" /></li>
<li>Email: <input name="contact_email" type="text" /></li>
<li><input type='submit' /></li>
</ul>
<?php } ?>
wp_mail(). There is no excuse to use plainmail(). ;)