-
-
Save Maikuolan/62edcd757569675df143 to your computer and use it in GitHub Desktop.
Refer to the included comments.
This file contains 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 | |
/** | |
* "Undefined index" means that you're trying to fetch data from a variable | |
* that doesn't exist (or isn't "defined"). Looking at your code here, | |
* personally, what I would do here, firstly, is check whether your $_REQUEST | |
* variables are empty, and if they're not, *then* set your $action variable, | |
* rather than before. | |
*/ | |
if (!empty($_REQUEST['action'])) { | |
$action = $_REQUEST['action']; | |
?> | |
<form action="contact.php" method="POST" enctype="multipart/form-data"> | |
<input type="hidden" name="action" value="submit"> | |
Your name:<br> | |
<input name="name" type="text" value="" size="30"/><br> | |
Your email:<br> | |
<input name="email" type="text" value="" size="30"/><br> | |
Your message:<br> | |
<textarea name="message" rows="7" cols="30"></textarea><br> | |
<input type="submit" name="submit" value="Send email"/> | |
</form> | |
<?php | |
} else { | |
/** Same principle as with the "action" variable, we'll do the same here. */ | |
if (empty($_REQUEST['name']) || empty($_REQUEST['email']) || empty($_REQUEST['message'])) { | |
echo 'All fields are required, please fill <a href=\'\'>the form</a> again.'; | |
} else { | |
$name = $_REQUEST['name']; | |
$email = $_REQUEST['email']; | |
$message = $_REQUEST['message']; | |
$from = 'From:' . $name . $email . "\r\nReturn-path: " . $email; | |
$subject = 'Message sent using your contact form'; | |
mail('[email protected]', $subject, $message, $from); | |
echo 'Email sent!'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment