Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Sending email content to two places

sending email to mail and sepperate page

1:03 am on Feb 23, 2007 (gmt 0)

New User

10+ Year Member

joined:Feb 22, 2007
votes: 0

Could someone please help me.

I need to send content from a form to email and to the adjoining script. I was using $_POST to get both sets of information, but the adjoining script will not show the inputs.

The scripts are as follows:


<?php //send email script

$message .= "Salutation:".$_POST['salutation']."\n";
$message .= "First Name:".$_POST['first_name']."\n";
$message .= "Last Name:".$_POST['last_name']."\n\n";
$message .= "Address:".$_POST['no_and_street']."\n";
$message .= "Address:".$_POST['suburb']."\n";
$message .= "Address:".$_POST['post_code']."\n\n";
$message .= "Home Phone:".$_POST['home_phone']."\n";
$message .= "Work Phone:".$_POST['work_phone']."\n";
$message .= "Mobile:".$_POST['mobile']."\n\n";
$message .= "Email:".$_POST['email']."\n\n";
$message .= "Description:".$_POST['description']."\n";

mail( "dave@example.com.au", "Contact Form Information",
$message, "From: example.com.au" );
header( "Location: thankyou.php" );


And the section of 'thankyou.php'

print "<p>Thank you {$_POST['salutation']} {$_POST['first_name']} {$_POST['last_name']} for submitting our contact form.</p>";
print "<p>Your contact details are:
<li>{$_POST['no_and_street']}, {$_POST['suburb']}, {$_POST['post_code']}</li>
<li>Home phone - {$_POST['home_phone']}, work phone - {$_POST['work_phone']}, mobile - {$_POST['mobile']}</li>
<li>Email - {$_POST['email']}</li>

There is more of the 'thankyou.php' script, but I have only included the necessary bits. The 'thankyou.php' script displays the above information like this:

Thank you for submitting our contact form.

Your contact details are:

, ,
Home phone - , work phone - , mobile -
Email -

As you can see, the $_POST inputs are not showing up, but they were before I had written 'mailscript.php'. The form used to point to 'thankyou.php' and now points to 'mailscript.php'.

If possible, I want to send the information to the email and to a page thanking the person who submitted the form, and showing them the information they submitted.


[edited by: coopster at 3:58 am (utc) on Feb. 23, 2007]
[edit reason] generalized domain [/edit]

3:39 am on Feb 23, 2007 (gmt 0)


WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
votes: 106

your Location header is telling the browser to do a http GET request.
the new get request knows nothing about your browser's previous http POST, so it has no values for those form parameters.
why not combine them into one script or include one into the other?
10:00 am on Feb 23, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
votes: 0

Exactly, as Phranque said redirecting looses all POST data,

it's easier if you

mail( "dave@example.com.au", "Contact Form Information",
$message, "From: example.com.au" );

Moreover always filter your data before sending it outside, otherwise your script can be used to send spam


8:40 pm on Feb 23, 2007 (gmt 0)

New User

10+ Year Member

joined:Feb 22, 2007
votes: 0

Thanks mcibor, but how do you filter the contents of the email to stop spamming?
4:19 am on Feb 24, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 3, 2005
votes: 0

you can use addslashes [in.php.net] and htmlentities [in.php.net] functions to filter your incoming data.
10:59 am on Feb 24, 2007 (gmt 0)

New User

10+ Year Member

joined:Feb 22, 2007
votes: 0

Thanks guys for the input, but I am way to much of a newbie to go that deep into php. For the moment I will have to take the chance that noone uses the email to spam.

Thanks for your help as I can now do what I wanted to do.



Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members