g7labs Posted October 4, 2014 Share Posted October 4, 2014 Hi, i have a script problem as I am a graphic designer with zero php knowledge. I have a contact script that sends emails but they are blank. Meaning all text fields are not sending. If you could correct this for me thanks in advance. Here is my hacked up script that sends email with empty fields: <!DOCTYPE html> <html lang="en"> <?php if (!count($_POST)){ ?> <form method="post" id="myform" action="<?php echo $_SERVER['PHP_SELF']; ?>"> </form> <?php }else{ ?> <?php $mail = $_POST['email']; /*$subject = "".$_POST['subject'];*/ $to = "...admin@yahoo.com"; $subject = "Message from Digital ......"; $headers = "From: YourName <noreply@..........com>"; $message = "Message from YourName\n"; $message .= "\nName: " . $_POST['Name']; $message .= "\nEmail: " . $_POST['Email']; $message .= "\nMessage: " . $_POST['Message']; //Receive Variable $sentOk = mail($to,$subject,$message,$headers); } ?> <!-- END SEND MAIL SCRIPT --> </html> This is all that sends: Message from YourNameName: Email: Message: Quote Link to comment https://forums.phpfreaks.com/topic/291427-contact-form-script-not-sending-fields/ Share on other sites More sharing options...
Frank_b Posted October 4, 2014 Share Posted October 4, 2014 I only see <form></form>. Where are the input fields? the index for the $_POST array has to be the same as the name attribute inside your input fields and are case sensitive. eg: <input type="text" name="email" /> <==> $_POST['email'] And to be honest: your code is a nightmare :-) Quote Link to comment https://forums.phpfreaks.com/topic/291427-contact-form-script-not-sending-fields/#findComment-1492700 Share on other sites More sharing options...
cyberRobot Posted October 8, 2014 Share Posted October 8, 2014 Side note: Using the raw value from PHP_SELF in the form's action attribute opens your website up to XSS attacks. To have the form submit to the same page, you can leave the action attribute blank. <form method="post" id="myform" action=""> Quote Link to comment https://forums.phpfreaks.com/topic/291427-contact-form-script-not-sending-fields/#findComment-1492989 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.