# How to redirect after submitting a PHP Mail Form?

**URL:** https://forum.kirupa.com/t/how-to-redirect-after-submitting-a-php-mail-form/87177
**Category:** web dev
**Created:** [April 19, 2005, 1:44am UTC](https://forum.kirupa.com/t/how-to-redirect-after-submitting-a-php-mail-form/87177 "2005-04-19T01:44:49Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Hellion](https://avatars.discourse-cdn.com/v4/letter/h/6a8cbe/32.png) [@Hellion](https://forum.kirupa.com/u/Hellion)
#### Post date: [April 19, 2005, 1:44am UTC](https://forum.kirupa.com/t/how-to-redirect-after-submitting-a-php-mail-form/87177/1 "2005-04-19T01:44:49Z")

</div>

[color=black]Hi People:[/color]Kirupa posted this PHP mail tutorial a bit ago. His code goes like this:

[color=#0000ff]\<?[/color][color=#000050]php[/color] [color=#006610]if[/color]color=#0000ff[/color] [color=#0000ff]{[/color] [color=#000050]$to[/color] [color=#0000ff]=[/color] [color=#666666]“you@you.com”[/color]; [color=#000050]$subject[/color] [color=#0000ff]=[/color] [color=#666666]“Form Tutorial”[/color]; [color=#000050]$name\_field[/color] [color=#0000ff]=[/color] [color=#000050]$\_POST[/color][color=#0000ff][[/color][color=#666666]‘name’[/color][color=#0000ff]][/color]; [color=#000050]$email\_field[/color] [color=#0000ff]=[/color] [color=#000050]$\_POST[/color][color=#0000ff][[/color][color=#666666]‘email’[/color][color=#0000ff]][/color]; [color=#000050]$message[/color] [color=#0000ff]=[/color] [color=#000050]$\_POST[/color][color=#0000ff][[/color][color=#666666]‘message’[/color][color=#0000ff]][/color]; [color=#000050]$body[/color] [color=#0000ff]=[/color] [color=#666666]“From: $name\_field  
E-Mail: $email\_field  
Message:  
$message”[/color]; [color=#000050]echo[/color] [color=#666666]“Data has been submitted to $to!”[/color]; [color=#000050]mail[/color][color=#0000ff]([/color][color=#000050]$to[/color], [color=#000050]$subject[/color], [color=#000050]$body[/color][color=#0000ff])[/color]; [color=#0000ff]}[/color] [color=#006610]else[/color] [color=#0000ff]{[/color] [color=#000050]echo[/color] [color=#666666]“blarg!”[/color]; [color=#0000ff]}[/color] [color=#0000ff]?\>[/color] Once you set all your info, you put your page on the net and when you submit the form, it displays a page with a message saying your data has been submitted to whatever address you chose, right?

I’d like, after submitted the message, to redirect the page to the same contact page, or for example, to another page in the site. Not to display the page with the echo command.

Can anybody teach me how to modify the PHP code to do just that?

The address to the tutorial is [http://www.kirupa.com/web/php\_contact\_form2.htm](http://www.kirupa.com/web/php_contact_form2.htm)  
for your reference.

Thanks in advance for your help.  
Keep up your great work.
