Hi I am currently use this code but , this is not working plz help me. we use the variables in the mail() function to send an e-mail: <?php $to = "someone@example.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "someonelse@example.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> <html> <body> <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "someone@example.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?> </body> </html> Attorney Advertising
Hello.. To start with, you have to be as accurate as possible when programming: echo "<form method='post' action='mailform.php' enctype='multipart/form-data'> You are using the post method in your form which is good but then u start using $_REQUEST.. Replace them with $_POST to catch the veriables you are posting. As for your condition of sending a mail: isset($_REQUEST['email']) I could fill in a form with email only, so without subject or message while still being sent.. You can get really advanced in this, but to keep it basic: $err = ""; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; if((isset($email) && $email!=NULL) && (isset($subject) && $subject!=NULL) && (isset($message) && $message!=NULL)){ // send your mail } else{ $err = "The form could not be sent, please fill in:<br/>"; if($email==NULL){ $err .= "- your email<br/>"; } if($subject==NULL){ $err .= "- a subject<br/>"; } if($message==NULL){ $err .= "- a message<br/>"; } echo $err; }
you only use that enctype for file uploads. the regular x-www-form-urlencoded or default is the correct to use. And its the default so there's no need to even bother with including the enctype. http://www.w3.org/TR/html401/interact/forms.html#h-17.3
I don't think that influences it. The multipart/form-data (from what I've read) opens up two connections (ascii/binary) causing extra overhead. Course that overhead is minor if its on an infrequently used form. To me though, the form-data setting is telling the processing script that its going to get a larger than usual form submission. And it should apply no matter what server side script is handling it (perl,php, asp, whatever).