html - Add extra INPUT to contact form email PHP -
html - Add extra INPUT to contact form email PHP -
i'm using php found sending contact form site.
the html looks this:
<div id="wrap"> <div id='form_wrap'> <form id="contact-form" action="javascript:alert('success!');"> <p id="formstatus"></p> <input type="text" name="name" value="" id="name" placeholder="voornaam" required/> <input type="text" name="email" value="" id="email" placeholder="e-mail adres" required/> <textarea name="message" value="your message" id="message" placeholder="uw vraag of projectomschrijving" required></textarea> <input type="submit" name ="submit" value="offerte aanvragen" /> </form> </div> </div>
the php looks this:
<?php define("webmaster_email", 'your@emailadress.com'); error_reporting (e_all ^ e_notice); function validateemail($email) { $regex = '/([a-z0-9_.-]+)'. # name '@'. # @ '([a-z0-9.-]+){2,255}'. # domain & perchance subdomains '.'. # period '([a-z]+){2,10}/i'; # domain extension if($email == '') homecoming false; else $eregi = preg_replace($regex, '', $email); homecoming empty($eregi) ? true : false; } $post = (!empty($_post)) ? true : false; if($post) { $name = stripslashes($_post['name']); $email = trim($_post['email']); $subject = stripslashes($_post['subject']); $message = stripslashes($_post['message']); $error = ''; // check name if(!$name || $name == "name*") $error .= 'please come in name.<br />'; // check email if(!$email || $email == "email*") $error .= 'please come in e-mail address.<br />'; if($email && !validateemail($email)) $error .= 'please come in valid e-mail address.<br />'; // check message if(!$message) $error .= "please come in message. <br />"; if(!$error) { $mail = mail(webmaster_email, $subject, $message, "from: ".$name." <".$email.">\r\n" ."reply-to: ".$email."\r\n" ."x-mailer: php/" . phpversion()); if($mail) echo 'ok'; } else echo '<div class="formstatuserror">'.$error.'</div>'; }?>
it works great! need add together few more inputs in form. know how add together html. instance added one:
<input type="text" name="lastname" value="" id="lastname" placeholder="achternaam" required/>
but can't find way add together input email receive in mailbox... add together in php? tried lots of things...
hope guys can help me out!
david
after these lines:
$name = stripslashes($_post['name']); $email = trim($_post['email']); $subject = stripslashes($_post['subject']); $message = stripslashes($_post['message']);
you instanciate variable containing value field (lastname):
$lastname = stripslashes($_post['lastname']);
then validate input if it's empty or else:
// check message if(!$lastname ) $error .= "please come in lastname. <br />";
and finally, utilize variable lastname display on email message:
"from: ".$name." ".$lasname." <".$email.">\r\n"
et voilĂ !
edit: if want utilize input on message, have $message
variable, , can :
if(!$error) { $message .= "<p>message sent $lastname"; ...
php html css email
Comments
Post a Comment