Reputation: 43
I have a form in my HTML/CSS and I need to give it an action. I want it to email me with the fields filled out with the results. I heard this is possible using PHP but I am quite a PHP beginner.
Here is my html
http://codepen.io/anon/pen/JXpXZa
I have found the below PHP but need to know how to add one for the Twitter username field
<?php
if($_POST["submit"]) {
$recipient="[email protected]";
$subject="Form to email message";
$sender=$_POST["sender"];
$senderEmail=$_POST["senderEmail"];
$message=$_POST["message"];
$mailBody="Name: $sender\nEmail: $senderEmail\n\n$message";
mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
$thankYou="<p>Thank you! Your message has been sent.</p>";
}
?>
Upvotes: 0
Views: 400
Reputation: 150
<?php
//give a name attribute for all control in the html page e.g name="twitter" and use the bellow modified code
if($_POST["submit"]) {
$recipient="[email protected]";
$subject="Form to email message";
$sender=$_POST["sender"];
$twittername = $_POST['twitter']
$senderEmail=$_POST["senderEmail"];
$message=$_POST["message"];
$mailBody="Name: $sender \n $twitter \nEmail: $senderEmail\n\n$message";
mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
$thankYou="<p>Thank you! Your message has been sent.</p>";
}
?>
Upvotes: 1