PHP Mailing Form - Change "Echo" to "Get URL"

I have a simple PHP mailing form on my site.  When the user submits, they get an "echo" which looks bizarre and unsightly.  I'd like users to go to a specific page "thankyou.html) after submitting my small form.

What changes should I make in the PHP coding?
<?php
 
$message = '';
foreach ($_POST as $key => $value) {
$message .= "$key = $value \r\n";
}
if (!mail('customerservice@virtual-actor.com', '++ 100 WEBSITES PROMO - personal check ++', $message)) {
$fp = fopen('unsent_va.txt', 'a');
fwrite($fp, date('r') . "\r\n");
fwrite($fp, $message . "\r\n");
fclose($fp);
}
echo "<p>Thanks for submitting!</p>";
 
?>
</body>
</html>

Open in new window

LyricalPinkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Bizarre and unsightly?  Is it something other than this: <p>Thanks for submitting!</p> ?
0
LyricalPinkAuthor Commented:
Yes, I don't want it linking to that random page -- which is just white and includes "Thanks for submitting".  I'd like to link it to a "thankyou.html" page.
0
Ray PaseurCommented:
To redirect to the thank you page, you would use something like this...
<?php
 
$message = '';
foreach ($_POST as $key => $value) {
   $message .= "$key = $value \r\n";
}
 
if (!mail('customerservice@virtual-actor.com', '++ 100 WEBSITES PROMO - personal check ++', $message)) {
   $fp = fopen('unsent_va.txt', 'a');
   fwrite($fp, date('r') . "\r\n");
   fwrite($fp, $message . "\r\n");
   fclose($fp);
}
 
header('Location: thankyou.html');
exit; 
?>

Open in new window

0
Ray PaseurCommented:
The exit statement follows the header statement because header() is asynchronous, and the script keeps executing.

Note that you could redirect to a "thoughtful" script with a header statement that knew whether the email worked or not.  Interesting idea, maybe.

Best regards, ~Ray
<?php
 
$message = '';
foreach ($_POST as $key => $value) {
   $message .= "$key = $value \r\n";
}
 
$mail_worked = 'Y';
if (!mail('customerservice@virtual-actor.com', '++ 100 WEBSITES PROMO - personal check ++', $message)) {
   $fp = fopen('unsent_va.txt', 'a');
   fwrite($fp, date('r') . "\r\n");
   fwrite($fp, $message . "\r\n");
   fclose($fp);
   $mail_worked = 'N';
}
 
header("Location: thankyou.php?code=$mail_worked");
exit; 
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
Would the OP author kindly explain why a grade of "B" was given here?  I presented an EXACT solution.

Please follow the grading guidelines.  If you don't understand the grading guidelines, ask a Moderator to help you!  

Looking forward to a revised grade of "A" or a clear explanation of the grading guidelines you used to determine that the answer was so incomplete as to warrant being marked down to a "B".

Thank you.  ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.