Created
January 19, 2011 04:57
-
-
Save donut/785711 to your computer and use it in GitHub Desktop.
An introduction to sending emails and redirecting the user with PHP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Emails in php are typically sent with the `mail()` function.You can see the | |
* details of that funciton here: | |
* http://php.net/manual/en/function.mail.php | |
* Then, to redirect the user you can use the `header()` function. You can | |
* learn more about that function here: | |
* http://us2.php.net/manual/en/function.header.php Here's a | |
* very simple solution. I'll assume you've already populated the variables I | |
* use. | |
*/ | |
$was_sent = mail($to, $subject, $message); | |
if ($was_sent === false) { | |
// message was not sent | |
} else { | |
// message was sent, redirect user | |
header('Location: http://amiblind.com'); | |
// nothing after this is executed. | |
} | |
/* Whenever I have any programming questions I usually go to stackoverflow.com | |
* first. For PHP, the best resource is really the main php.net website. Use | |
* the search field there and make sure to check the comments, many times there | |
* are solutions to common problems there. And if you need more help, feel free | |
* to contact me again. I'm happy to help. | |
* | |
* Oh, and you should be able to make a copy of this file gist.github.com and | |
* make changes and link me to it if you have more questions. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment