Can someone please give me detailed tutorial / guide on how to make a contact form ? I know XHTML and CSS, and just a very little bit PHP Thanks in advance.
suppose your form is passing the following name, email, phone, message .. and let's suppose it's a POST method so here's your script $name = $_post['name']; $email = $_post['email']; $phone = $_post['phone']; $message = $_post['message']; if ($name && $email && $phone && $message) { // check the required fields $body = "Yo Xabber, wassup ? <br><br>\n $name has just fill out the contact form.<br>\n You may contact $name by phone at $phone or by email at $email .<br>\n"; $body .= "Here is what $name wants from you:<br><br>\n"; $body .= $message; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: $name <$email>' . "\r\n"; mail("xabber@xabber.com", "YourSite.com - Contact Form", $body, $headers); } else { echo "Yo, you gotta fill out the required fields .. go back and fill it out"; } PHP: sorry for too much kidding is this good for you ? - then gimme a rep Hope this helps
try: http://www.zymic.com/view_tutorial.php?id=87 If you ever need a tutorial, my fave site is: http://www.pixel2life.com
here's some more contribution for you function isValidAddress( $email, $check = true ) { if (!ereg('' . '^' . '[-!#$%&\'*+/0-9=?A-Z^_a-z{|}~]' . '(\\.?[-!#$%&\'*+/0-9=?A-Z^_a-z{|}~])*' . '@' . '[a-zA-Z](-?[a-zA-Z0-9])*' . '(\\.[a-zA-Z](-?[a-zA-Z0-9])*)+' . '$' , $email ) ) return false; list( $local, $domain ) = split( "@", $email, 2 ); if ( strlen($local) > 64 || strlen($domain) > 255 ) return false; if ( $check && !gethostbynamel( $domain ) ) return false; return true; } function isValidPhone($phone) { $phone = preg_replace("^\D^", "", $phone); $phone = preg_replace("^\s^", "", $phone); return (strlen($phone) >= 10 ? true : false); } PHP: just copy and paste these functions into your php, and after that in your script where it says if ($email && $phone && $message && $name) just replace that line with the following if (isValidAddress($email, true) && isValidPhone($phone) && $name && $email) so now the script will check for valid email and valid US 10 digit phone with area code NOTE: 1. the isValidAddress function checks also for validity of the domain (actually checks if the domain exists at all) of the email if the second argument is set to "true" and doesn't check it if set to "false" 2. the isValidAddress function is not written by me
I created a contact form, and a PHP-file "sendmail.php". But when I click the submit button, the computer asks me whether I want to run the PHP-file, or save it to disk, like you get when you download a file. What's wrong ?
Hi Aron, Thanks for replying. I'm not using Apache. I just get the message no matter what the content of the PHP-file is. Like when I copy and paste code on this site, for instance.
"stats" code is susceptible to header injection because of the unvalidated $name variable in the email headers. You should remove $name or validate it first. You can find a mail form that protects against all this via the link in my signature. Lapzwans: you can't run PHP on your computer unless you have the correct software installed. If you're planning on doing a lot of editing of PHP files on your computer I suggest a package called "XAMPP" (google it) - it contains all you'll need to execute PHP files and more.