contact form PHP redirect is not working

前端 未结 7 477
迷失自我
迷失自我 2021-01-20 01:42

I im trying to redirect to my homepage after submitting a message on my contact form, the form sends the email but I get this message:

Array
(
    [name] =&g         


        
7条回答
  •  庸人自扰
    2021-01-20 01:56

    You get this warning because you output to the screen your variables' values and redirecting with header after that.

    Headers cannot be sent after your print something (echo , print_r ...). In order to fix it , follow the next code:

    $name = $_POST['name']; //no echo 
    $company = $_POST['company'];//no echo 
    $email =  $_POST['email'];//no echo 
    $content = $_POST['content'];//no echo 
    
    
    
    
    $mail_to = 'info@webelite.se';
    $subject = 'Lilla form'.$name;
    
    
    
    $body_message = 'From: '. $name . "\n"; 
    $body_message .= 'company: '. $company . "\n";
    $body_message .= 'E-mail: '. $email ."\n";
    $body_message .= 'Message: '. $content;
    
    
    
    $headers = 'From: '. $mail_name . "\r\n";
    $headers .= 'Reply-To: '. $email ."\r\n";
    
    
    
    $success = mail($mail_to, $subject, $body_message, $headers);
    
    
    
    //echo "
    ";
    //print_r($_POST);
    

提交回复
热议问题