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> 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. 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 = '[email protected]'; $subject = 'Form filled out'; $body = print_r($_POST,true); $from = 'From: [email protected]'; $param5 = '-f [email protected]'; 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 Link to comment https://forums.phpfreaks.com/topic/83504-send-form-email/#findComment-424891 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.