0

I want to redirect the user to a thank you page after the form is sucessfully submitted. I use the below script but get error message. please help.

<?php
session_start();

$name = check_input($_POST['name'], "Name cannot be empty.");
$email     = check_input($_POST['email'], "Email address cannot be empty.");

if(!preg_match("/^([A-Za-z\s\-]{2,45})$/i", $name))
{ 
show_error("name not valid.");
}

if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Email address not valid.");
}

htmlentities ($message, ENT_QUOTES);

require("../PHPMailer/class.phpmailer.php");

$mail = new PHPMailer();

$mail->From     = "$email";
$mail->AddAddress("myfriend@example.net");

$mail->Subject  = "An HTML Message";
$mail->Body     = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!";
$mail->WordWrap = 50;

foreach(array_keys($_FILES['photo']['name']) as $key) {
$source = $_FILES['photo']['tmp_name'][$key]; // location of PHP's temporary file for this.
$filename = $_FILES['photo']['name'][$key]; // original filename from the client

$mail->AddAttachment($source, $filename);
}

/* Redirect visitor to the thank you page */
header('Location: pthankyou.php');
exit();

function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlentities($data);
if ($problem && strlen($data) == 0)
{
    show_error($problem);
}
return $data;
}

function show_error($Error)
{}
?>

Error Message

Warning: Cannot modify header information - headers already sent by (output started at PHPMailer/class.phpmailer.php:1370) in process.php on line 66

Mandy Mo
  • 22
  • 1
  • 4

1 Answers1

1

redirect() is a particular php built-in function that needs to be called before any output.

An output could be:

  • echo
  • html tags
  • var dumping
  • spacese before <?php tag

However, I didn't see redirect() included in your code. If you want more specific help, you have to include the snippet of code where your issue is.

Nyk
  • 83
  • 9
DonCallisto
  • 29,419
  • 9
  • 72
  • 100