0

I am able to send an e-mail through SMTP and PHPMailer but I keep getting this error message.

Warning: Cannot modify header information - headers already sent by (output started at /home/admin/public_html/inc/phpmailer/class.smtp.php:181) in /home/admin/public_html/contact/index.php on line 79

After sending my e-mail I want to forward the user to a thank-you page. This is my php to do so.

if (($noName == false) AND ($noEmail == false) AND ($badEmail == false) AND ($noMessage == false)) { 
        header('Location: index.php?status=sent');
        exit;
}

I am using the SMTP PHPMailer class to do so.

    //Create a new PHPMailer instance
    $mail = new PHPMailer();    
    $mail->IsSMTP();
    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages
    $mail->SMTPAuth = true; // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 465; // or 587
    $mail->IsHTML(true);
    $mail->Username = "******";
    $mail->Password = "******";

Any suggestions as to why this is throwing this error message?

Ryan Salmons
  • 1,429
  • 10
  • 21
  • 42
  • 1
    what Have tried so far? have you tried including an `ob_start`? – Kim Oliveros May 15 '14 at 03:45
  • Though this is a generic symptom addressed by the linked duplicate question, in this specific case the cause is having `$mail->SMTPDebug = 1;`, which will cause the script to output content prior to you trying to send a header. Set that to `0` and the problem will go away. – Synchro Sep 03 '14 at 11:41

0 Answers0