Jump to content
xisto Community
Sign in to follow this  
FaLgoR

Contact Form Contact form using mail() function

Recommended Posts

In first place, make an html page with the form.<html><head><title>My first form with PHP</title></head><body><form action="sendmail.php" method="post"><table border="0"><tr><td>Name:</td><td><input type="text" name="name"></td></tr><tr><td>E-Mail:</td><td><input type="text" name="email"></td></tr><tr><td>Subject:</td><td><input type="text" name="subject"></td></tr><tr><td>Mesage:</td><td><textarea name="mesage"></textarea></td></tr><tr><td><input type="submit" value="Send Mesage"></td><td><input type="reset" value="Reset Form"></td></tr></table></form></body></html>OK, now, lets make sendmail.php:<?$myemail = 'yourmail@blah.com'; // Put here your e-mail addressmail($myemail,$subject,$mesage,$email) // To, Subject, Mesage and Fromecho 'Thank you for your e-mail!';?>Simple, huh?Any questions just post here.

Share this post


Link to post
Share on other sites

THE SENDMAIL.PHP can be improved much further by using the following code

[/br]<?php [br]/* recipients */ [/br]$to  = $_POST["email"];  . ", "; // note the comma [br]$to .= "any-extra-people-u-want-to-send-email@example.com"; [/br][br]/* subject */ [/br]$subject = $_POST["subject"]; [br][/br]/* message */ [br]$message = <<<END [/br]<html> [br]<head> [/br]<title>$_POST["subject"]</title> [br]</head> [/br]<body> [br]$_POST["message"][/br]</body> [br]</html> [/br]END;[br][/br]/* To send HTML mail, you can set the Content-type header. */ [br]// SENDING EMAIL IN HTML FORMAT RATHER THAN TEXT IN PREVIOUS EXAMPLE[br][/br]$headers  = "MIME-Version: 1.0\r\n"; [/br]$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; [br][/br]/* additional headers */ [br]$headers .= "To: $_POST["name"]<$_POST["email"]>\r\n"; [/br]$headers .= "From: ANYGOOD NAME <YOUR-EMAIL@example.com>\r\n";  // Your address[br]$headers .= "Cc: EXAMPLE@example.com\r\n";  // Send CC[/br]$headers .= "Bcc: BCC-EXAMPLE@example.com\r\n";  // SEND BCC[br][/br]/* and now mail it */ [br][/br]mail($to, $subject, $message, $headers); [br]?>[/br]


The code in previous example is perfect, but the one above can be used to improve the email exprence

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.