I have a short php (with html elements) and my objective is to submit the form content on button click, then, redirect to another page afterwards. However, the email goes, but doesn’t get to the destination email, also, the redirect is giving me this error: " Warning : Cannot modify header information - headers already sent by (output started at /home/runner/phpemaildemo/emailprocess.php:1) in /home/runner/phpemaildemo/emailprocess.php on line 18"
ANY INSIGHT WILL BE APPRECIATED.
Here is my php script:<?PHP $email = $_POST["emailaddress"]; $to = "firstname.lastname@example.org"; $subject = "This is Gift's test email"; $headers = "From: $email\n"; $message = "Your information was received successfully.\n Email Address: $email"; $user = "$email"; $usersubject = "Thank You"; $userheaders = "From: email@example.com\n"; $usermessage = "Thank you, Mr. Xt, your subsription have been received."; mail($to,$subject,$message,$headers); mail($user,$usersubject,$usermessage,$userheaders); //redirection to any page you desire header('Location: thank_you.php'); ?>
Here is my html (index.php):PHP Email Test
<form method="POST" name="contactform" action="emailprocess.php"> <p> <label for='name'>Your Name:</label> <br> <input type="text" name="name"> </p> <p> <label for='email'>Email Address:</label> <br> <input type="text" id="emailaddress"name="email" placeholder="Enter Your email address"> <br> </p> <p> <label for='message'>Message:</label> <br> <textarea name="message"></textarea> </p> <input type="submit" value="Send Email"> <br> </form>