0

I am trying to get PHP Mailer Script to redirect after the message has been sent.

    if(!$mail->Send()) {
        $data['success'] = false;
        $data['message'] = 'There were errors with your form, please refer to the warnings!';

    } else {
        $data['success'] = true;
        $data['message'] = 'Success! Your message was sent. I will contact you shortly.';
    }
}

    echo json_encode($data);
Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35

1 Answers1

0

We can suppose you want to redirect the user to Welcome.php when Email is sent successfully. So you need to change the location with HTTP header.

Here an example

    if(!$mail->Send()) {
        $data['success'] = false;
        $data['message'] = 'There were errors with your form, please refer to the warnings!';

    } else {
        $data['success'] = true;
        $data['message'] = 'Success! Your message was sent. I will contact you shortly.';
    header('Location: Welcome.php');
    }
}

    echo json_encode($data);
Tech Spot
  • 464
  • 3
  • 10