Dysan Posted December 28, 2007 Share Posted December 28, 2007 How do I send the data entered in this form, to my email inbox? <html> <body> <form action="insert.php" method="post"> Firstname: <input type="text" name="firstname" /> Lastname: <input type="text" name="lastname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/83504-send-form-email/ Share on other sites More sharing options...
p2grace Posted December 28, 2007 Share Posted December 28, 2007 Something like this should work. <? if(isset($_POST['firstname'])){ // Grab Post Vars $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $age = $_POST['age']; // Set email vars $from = ""; $cc = ""; $bcc = ""; $headers = "From: $from \r\n"; $headers .= "Cc: $cc \r\n"; $headers .="Bcc: $bcc \r\n"; $message = "First Name = $firstname \n Last Name = $lastname \n Age = $age"; $subject = "Email Form"; $headers .="Content-Type: text/plain; charset=UTF-8; format=flowed\n". "MIME-Version: 1.0\n". "Content-Transfer-Encoding: 8bit\n". "X-Mailer: PHP\n"; // Send Email @mail($to, $subject, $message, $headers); } ?> <html> <body> <form action="insert.php" method="post"> Firstname: <input type="text" name="firstname" /> Lastname: <input type="text" name="lastname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> This is obviously very basic. You should validate and clean the input before sending the email. Quote Link to comment https://forums.phpfreaks.com/topic/83504-send-form-email/#findComment-424851 Share on other sites More sharing options...
kenrbnsn Posted December 28, 2007 Share Posted December 28, 2007 The quickest way would be something like this: <?php if (isset($_POST['submit'])) { $to = 'your.email@here.com'; $subject = 'Form filled out'; $body = print_r($_POST,true); $from = 'From: formpost@yourdomain.com'; $param5 = '-f formpost@yourdomain.com'; mail($to,$subject,$body,$from,$param5); } ?> <html> <body> <form method="post"> Firstname: <input type="text" name="firstname" /> Lastname: <input type="text" name="lastname" /> Age: <input type="text" name="age" /> <input type="submit" name="submit" /> </form> </body> </html> Ken Quote Link to comment https://forums.phpfreaks.com/topic/83504-send-form-email/#findComment-424891 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.