The last tutorial was about a PHP/MySQL counter for a client. The same client requested a simple contact form, with no AJAX, or other options. So, I used the PHP mail() function, wrapped in a simple XHTML form.
First, we create the XHTML form (contact.php):
<h1>Simple Contact Form</h1> <form name="form1" method="post" action="/simple_phpmysql_contact_form_tutorial/send_contact.html"> <p><input name="subject" type="text" id="subject" size="50" /> <label for="subject">Subject</label></p> <p><textarea name="detail" cols="50" rows="4" id="detail"></textarea> <label for="detail">Detail</label></p> <p><input name="name" type="text" id="name" size="50" /> <label for="name">Name</label></p> <p><input name="customer_mail" type="text" id="customer_mail" size="50" /> <label for="customer_mail">Email</label></p> <p><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></p> </form>
Next, we create the mail sending engine (/simple_phpmysql_contact_form_tutorial/send_contact.html):
<?php $subject ="$subject"; $message="$detail"; $mail_from="$customer_mail"; $header="from: $name <$mail_from>"; // Your email address $to ='someone@somewhere.com'; $send_contact=mail($to,$subject,$message,$header); // If message was successfully sent, display a message if($send_contact) { echo "Thank you for your interest. We will answer as soon as possible."; } else { echo "Error: The email was not sent. Check your server."; } ?>
That is all. You can include the contact.php file into your web site design.
Pingback: Husninet.com - Keep Share anything
That’s super simple No verification of any kind anywhere. Is this good to directly use these variables without any escaping? This kind of code result into cross site scripting vulnerabilities (remember mikeyy on twitter?)
A couple of points you might want to consider:
1. You should include the USER-AGENT IP address in the email.
2.
This is just an example of contact form framework. Additional checks should be placed in the form.
Great tutorial, I really learned a thing or two from this one. The example you provided is both neat and efficient, works perfectly for me!
Investment Blog´s last blog post..How to save money on real estate insurance?
cool post, that was help me solve my problem, of course works perfectly for me! many thanks
.-= maxomen’s last blog ..SEO Indexed Search Engine =-.
hey thanks for sharing this. I have been having a little difficulty with a contact form so this might just come in handy
I hope it helps you. Come back here and let us know.