Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2008-11-16
5
Medium Priority
?
252 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:LyricalPink
  • 4
5 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22971703
Bizarre and unsightly?  Is it something other than this: <p>Thanks for submitting!</p> ?
0
 

Author Comment

by:LyricalPink
ID: 22971777
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22971830
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
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1500 total points
ID: 22971842
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23262673
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question