Code
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->IsSMTP();
$mail->Host='smtp.gmail.com';
$mail->Port=587;
$mail->SMTPAuth=true;
$mail->SMPTSecure='tls';
$mail->Username='************';
$mail->Password='='************';';
$mail->setFrom('='************';', '='************';', 0);
$mail->addAddress('='************';');
$name = "First Name :" . $_POST['firstname'] . "<br>";
$email = "Email :" . $_POST['email'] . "<br>";
$number = "Contact Number :" . $_POST['number'] . "<br>";
$message = "message :" . $_POST['message'] . "<br>";
$truck = "Truck Selected :" . $_POST['item'] . "<br>";
$mail->isHTML(true);
$mail->Subject='='************';';
$mail->Body= "$name $email $number $message $truck";
if(!$mail->send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
header('Location: /index.php');
exit;
}
Does anyone know why this isn't redirecting to header?
It throws this error:
Code
Cannot modify header information - headers already sent by (output started at /websites/cv/cvcompton.co.nz/phpmailer/mail.php:34) in /websites/cv/cvcompton.co.nz/phpmailer/mail.php on line 35
Works on localhost, but not on web server
The email sends fine, it just doesn’t redirect to index
EDIT:
Quote
Functions that send/modify HTTP headers must be invoked before any output is made
Seems I needed to redirect to header before issuing an echo function
Code
if($mail->send()) {
header('Location: /index.php');
} else {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
exit;
}
This post was edited by Strickland on Jan 22 2020 01:10am