Dysan Posted February 1, 2008 Share Posted February 1, 2008 Hi, What's required to send the contents of a HTML form via email using PHP? Quote Link to comment https://forums.phpfreaks.com/topic/88972-email-form/ Share on other sites More sharing options...
A2xA Posted February 1, 2008 Share Posted February 1, 2008 here's a simple script that sends their comments and name <form action="mailto:youremail@yourdomain.com?subject=form submission" method="post" enctype="text/plain"> <table><tr><td> name: <INPUT NAME="name" TYPE="text" VALUE="name" SIZE=30><BR> <br> comments: <INPUT NAME="comments" TYPE="text" VALUE="comments" SIZE=50><BR> <br> </td></tr> <tr><td align=center> <INPUT TYPE="submit" value="submit" style="color: #ffffff; background-color: #000000"> </td></tr></table> </FORM> Just edit it to what you want and change your e-mail ask me if you need more help and it uses the mailto: function Quote Link to comment https://forums.phpfreaks.com/topic/88972-email-form/#findComment-455683 Share on other sites More sharing options...
Wolphie Posted February 1, 2008 Share Posted February 1, 2008 Using PHP is pretty easy. <?php $get = $_GET['do']; switch($get) { default: $form = '<form method="post" action="?do=sendmail">'; $form .= 'Email To: <input type="text" name="sendto" /><br />'; $form .= 'Your Email: <input type="text" name="email" /><br />'; $form .= 'Subject: <input type="text" name="subject" /><br />'; $form .= 'Message: <textarea name="message"></textarea><br />'; $form .= '<input type="submit" value="Send" />'; $form .= '<input type="hidden" name="form_check" value="1" />'; $form .= '</form>'; echo $form; break; case 'sendmail': if ( array_key_exists($_POST, 'form_check') ) { $sendto = $_POST['sendto']; $from= $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $message = nl2br($message); // Every new line is a break mail($sendto, $subject, $message, $from); echo 'Your mail has been successfully sent. Thank you for using our mail service.'; } else { echo 'Your mail failed to be sent, Please go back and try again.'; } break; } ?> This is a simple, and reasonably un-secure script, although not much damage could be done through an email. Please bear in mind, i rarely test my code that i write on here. So please let me know if you encounter any issues. Quote Link to comment https://forums.phpfreaks.com/topic/88972-email-form/#findComment-455695 Share on other sites More sharing options...
kenrbnsn Posted February 2, 2008 Share Posted February 2, 2008 As I've posted many times, the easiest way is to just dump the contents of the $_POST or $_GET array to your email: <?php if (isset($_POST['submit'])) mail('youremail@yourdomain.com','Contents of form',print_r($_POST,true),'From: youremail@yourdomain.com'); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/88972-email-form/#findComment-455752 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.