FencingFreak Posted May 9, 2009 Share Posted May 9, 2009 I can't seem to get the email to go through. Here is what I have coded so far, but I don't know enough to trouble shoot. Any one have some pointers? It is saved as a mailform.php <?php function spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field, FILTER_SANITIZE_EMAIL); //filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "myemail@gmail.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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/157437-i-am-new-to-php-and-having-trouble-setting-up-a-php-email-form/ Share on other sites More sharing options...
Maq Posted May 9, 2009 Share Posted May 9, 2009 Please use tags around code for proper syntax highlighting and formatting. You don't have a button named 'email' so it's never being submitted... Add to this line: Also, if you're using the post method why not use it? Replace all of the '$_REQUEST' with '$_POST'. Quote Link to comment https://forums.phpfreaks.com/topic/157437-i-am-new-to-php-and-having-trouble-setting-up-a-php-email-form/#findComment-830033 Share on other sites More sharing options...
Presto-X Posted May 9, 2009 Share Posted May 9, 2009 You could use something like this: <?PHP // CHECK TO SEE IF THE FORM HAS BEEN SUBMITTED if($_POST['validate'] != $_POST['frodo']){echo "<h3>Please go back and check the validation!</h3>";}else{ if (isset($_POST['submit'])&&($_POST['validate'] == $_POST['frodo'])){ // GET SUBMITTED FORM INFORMATION $sender = $_POST['email']; $message = $_POST['message']; $name = $_POST['name']; // WHO YOU WANT TO RECEIVE THE EMAIL $to = "myemail@gmail.com"; // YOUR EMAILS SUBJECT $subject = "Message from Example.com"; // WHO THE MESSAGE IS FROM $header = "From: $sender"; // SEND THE MESSAGE mail($to,$subject,$message,$headers); // THANK THE USER FOR USEING YOUR FORM echo "Thank you, ".$name .". Your message has been sent."; }else{ $random = rand(80000, 90000); ?> <form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" value="<?PHP echo $random; ?>" name="frodo" /> <table width="100%" border="0" cellspacing="4" cellpadding="0"> <tr> <td width="80" align="right"><label for="name">Name:</label></td> <td><input type="text" id="name" name="name" value="<?PHP echo $_POST['name'];?>" style="width:200px;" /></td> </tr> <tr> <td align="right"><label for="email">Email:</label></td> <td><input type="text" id="email" name="email" value="<?PHP echo $_POST['email'];?>" style="width:200px;" /></td> </tr> <tr> <td align="right"><label for="message">Message:</label></td> <td><textarea id="message" name="message" style="width:200px;"><?PHP echo $_POST['message']; ?></textarea></td> </tr> <tr> <td align="right"><label for="validate">Validate:</label></td> <td><div style="display:block; border:1px solid #DDDDDD; background-color:#EFEFEF; color:#666666; font-weight:bold; width:200px; padding:4px;"><?PHP echo $random; ?></div> <input id="validate" type="text" name="validate" id="validate" style="width:200px; border:1px solid #990000;" /></td> </tr> <tr> <td align="right"> </td> <td><input type="submit" name="submit" value="Submit" /></td> </tr> </table> </form> <?PHP }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/157437-i-am-new-to-php-and-having-trouble-setting-up-a-php-email-form/#findComment-830136 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.