I'm not a script person. i'm trying to add contact form for my website. There is something wrong i cant get 2 field into my email. can anyone please help me on it. Subject budget These 2 field i'm not getting into my email I have attached a copy of the process.php file along with a copy of the contact.html file. If any one could help would be greatly appreciated. http://swapnilmaind.com/test/contact2/contact_both.zip
Just paste the code here? Inside [ code ]-tags, that is - it will look like this: code goes here Code (markup):
Just paste the actual code in a post, within CODE-tags (look at the editor menu, you'll find an icon that looks like a mini version of a list, right next to the video button - paste the code)
HTML code <div class="content"> <h1>Contact</h1> <form method="post" action="process.php"> <div> <label for="name">Name *</label> <input name="name" type="text" id="name" placeholder="your full name"> </div> <div> <label for="subject">Subject *</label> <input name="subject" type="text" id="name" placeholder="subject"> </div> <div> <label for="email">Email Address *</label> <input name="email" type="email" id="email" placeholder="your email address"> </div> <div> <label for="budget">Budget *</label> <input name="budget" type="text" id="name" placeholder="Budget Range($250 and Above)"> </div> <div> <label for="comm">Your Message *</label> <textarea name="comments" rows="10" id="comm"></textarea> </div> <div class="hide"> <label for="spam">What is two plus two?</label> <input name="spam" type="text" size="4" id="spam"> </div> <div> <input type="submit" name="submit" value="Submit"> </div> </form> </div> PHP code <?php // Information to be modified $your_email = ""; // email address to which the form data will be sent $subject = "Logo Inquiry"; // subject of the email that is sent $thanks_page = "http://swapnilmaind.com/test/contact2/thankyou.html"; // path to the thank you page following successful form submission $contact_page = "contact.html"; // path to the HTML contact page where the form appears // Nothing needs to be modified below this line if (!isset($_POST['submit'])) { header( "Location: $contact_page" ); } if (isset($_POST["submit"])) { $nam = $_POST["name"]; $sub = $_POST["subject"]; $ema = trim($_POST["email"]); $bud = $_POST["budget"]; $com = $_POST["comments"]; $spa = $_POST["spam"]; if (get_magic_quotes_gpc()) { $nam = stripslashes($nam); $ema = stripslashes($ema); $com = stripslashes($com); $sub = stripslashes($sub); $bud = stripslashes($bud); } $error_msg=array(); if (empty($nam) || !preg_match("/^[\s.'\-\pL]{1,60}$/u", $nam)) { $error_msg[] = "The name field must contain only letters, spaces and basic punctuation (. - ')"; } if (empty($ema) || !filter_var($ema, FILTER_VALIDATE_EMAIL)) { $error_msg[] = "Your email must have a valid format, such as "; } $limit = 1000; if (empty($com) || !preg_match("/^[0-9\/\-\s'\(\)!\?\.,:;\pL]+$/u", $com) || (strlen($com) > $limit)) { $error_msg[] = "The Comments field must contain only letters, digits, spaces and basic punctuation ( ' - , . : ; / and parentheses), and has a limit of 1000 characters"; } if (!empty($spa) && !($spa == "4" || strtolower($spa) == "four")) { echo "You failed the bot test!"; exit (); } // Assuming there's an error, refresh the page with error list and repeat the form if ($error_msg) { echo '<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> <style> body {background: #f7f7f7; font: 100%/1.375 georgia, serif;padding: 20px 40px;} form div {margin-bottom: 10px;} .content {width: 40%; margin: 0 auto;} h1 {margin: 0 0 20px 0; font-size: 175%; font-family: calibri, arial, sans-serif;} label {margin-bottom: 2px;} input[type="text"], input[type="email"], textarea {font-size: 0.75em; width: 98%; font-family: arial; border: 1px solid #ebebeb; padding: 4px; display: block;} input[type="radio"] {margin: 0 5px 0 0;} textarea {overflow: auto;} .hide {display: none;} .err {color: red; font-size: 0.875em; margin: 1em 0; padding: 0 2em;} </style> </head> <body> <div class="content"> <h1>O dear!</h1> <p>Unfortunately, your message could not be sent. The form as you filled it out is displayed below. Make sure each field completed, and please also address any issues listed below:</p> <ul class="err">'; foreach ($error_msg as $err) { echo '<li>'.$err.'</li>'; } echo '</ul> <form method="post" action="', $_SERVER['PHP_SELF'], '"> <div> <label for="name">Name</label> <input name="name" type="text" size="40" maxlength="60" id="name" value="'; if (isset($_POST["name"])) {echo $nam;}; echo '"> </div> <div> <label for="email">Email Address</label> <input name="email" type="email" size="40" maxlength="60" id="email" value="'; if (isset($_POST["email"])) {echo $ema;}; echo '"> </div> <div> <label for="comm">Comments</label> <textarea name="comments" rows="10" cols="50" id="comm">'; if (isset($_POST["comments"])) {echo $com;}; echo '</textarea> </div> <div class="hide"> <label for="spam">What is two plus two?</label> <input name="spam" type="text" size="4" id="spam"> </div> <div> <input type="submit" name="submit" value="Send"> </div> </form> </body> </html>'; exit(); } $email_body = "Name of sender: $nam\n\n" . "Email of sender: $ema\n\n" . "COMMENTS:\n\n" . "$com" ; // Assuming there's no error, send the email and redirect to Thank You page if (isset($_REQUEST['comments']) && !$error_msg) { mail ($your_email, $subject, $email_body, "From: $nam <$ema>" . "\r\n" . "Reply-To: $nam <$ema>" . "Content-Type: text/plain; charset=utf-8"); header ("Location: $thanks_page"); exit(); } }
Well... I see you couldn't find the code-tags, but anyway... First off, in your HTML, you need to fix your IDs - you have multiple id="name", which is invalid code. For your other question, in the mail()-function, you're using "$subject" which is a set default value - not $sub which is defined later. As for $bud (budget) it's never used anywhere, and is therefore not part of the email. You'll need to use $bud somewhere, attach it to the email's text, or something.