14
Jan

If I have a web form script, how would I forward the form info to my e-mail using php? If possible, please cite a source or give a specific example of the code I would need to use. Thank you!


Answer:
ok you can send email with PHP with few easy steps.

this is how it's done.

First of all create your email form with HTML. this is code for it.

and if you want, you can modify it as you want.

Copy this code and paste it into section of the page.

 

Name:

 
     
Address:  
     
Tel:  
     
E-mail:  
     
Comments:  
     
   
 
 

OK now we will see how to create PHP page

create new PHP file and give it's name to "contact.php" and save it to the same folder where you save the HTML file that we created little time before.

and copy this code and paste it in to PHP file.

$to = "TOUR EMAIL ADDRESS HERE";

$Name = trim($_POST['Name']) ? trim($_POST['Name']) : '-';

$Address = trim($_POST['Address']) ? trim($_POST['Address']) : '_';

$Tel = trim($_POST['Tel']) ? trim($_POST['Tel']) : '_';

$Email = trim($_POST['Email']) ? trim($_POST['Email']) : '-' ;

$Comments = trim($_POST['Comments']) ? trim($_POST['Comments']) : '-' ;

$comment = wordwrap($comment, 100, "
\n");

$subject = "Customer Inquiries from web site";

$headers = "MIME-Version: 1.0\n";

$headers .= "Content-Type:text/html; charset=iso-8859-1\n";

$headers .= "From:$email\n";

$headers .= "Return-Path:$email\n";

$message = "

‘>http://www.w3.org/TR/html4/loose.dtd'>

Customer Inquire from Lalithajewellers web site

Customer Inquiries from web site

Name : $Name
Address : $Address
Telephone : $Tel
Email : $Email
Comments : $Comments

";

mail($to, $subject, $message, $headers);

//header("Location: http://" . $_SERVER['HTTP_HOST']

// . dirname($_SERVER['PHP_SELF'])

// . "/"

// . "confirm.htm");

exit();

?>

in the top of PHP code you can see "YOUR EMAIL ADDRESS HERE" replace it with your email address.

finished!

save this two file to 1 folder and upload it to PHP enabled server and test it .

If this hard to understand please tell me i'll explain it again if you want!

Good luck!

Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Tags: , , ,

This entry was posted on Monday, January 14th, 2008 at 10:10 pm and is filed under Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or TrackBack URI from your own site.

Leave a reply

Name (*)
Mail (*)
URI
Comment