After sending a contact form I got following error:
Warning: Cannot modify header information - headers already sent by (output started at /home/clientsc/public_html/mypage/wp-includes/general-template.php:2680) in /home/client/public_html/mypage/wp-includes/pluggable.php on line 1171
I got this error when I put the function below in the file named functions.php
function send_my_awesome_form(){
if (!isset($_POST['submit'])) {
// get the info from the from the form
$form = array();
$form['fullname'] = $_POST['fullname'];
$form['company'] = $_POST['company'];
$form['email'] = $_POST['email'];
}
// Build the message
$message = "Name :" . $form['fullname'] ."\n";
$message .= "Company :" . $form['company'] ."\n";
$message .= "Email :" . $form['email'] ."\n";
//set the form headers
$headers = 'From: Contact form <your@contactform.com>';
// The email subject
$subject = 'you got mail';
// Who are we going to send this form too
$send_to = 'myemail@gmail.com';
if (wp_mail( $send_to, $subject, $message, $headers ) ) {
wp_redirect(home_url( )); exit;
}
}
add_action('wp_head', 'send_my_awesome_form');
How can I solve this issue?