Well a lot of people keep asking about PHP mail forms. May be you wonder how yahoo, google, hotmail and many other webmail server are doing to be able to send information from one place in the world to the other just by filling out a form and clicking on a button. You can also do that. One way to do that is by using PHP. some might prefer to use ASP, etc. I will give the code and then explain that code.
Create a new PHP file and copy and paste the following code:
<?
//————————————————
// File: ‘phpmail.php’ // Func: using mail();
//————————————————
$Subject = “Test E-mail”;
$toEmail = “yourEmail@somewhere.com”;if(submit)
{
mail($fromEmail, $Subject, $nMessage.”\nFrom: “.$fromName.”<”.$fromEmail.”>”);
}
?>
<html>
<head>
<title>Mail Tutorial</title>
</head>
<body bgcolor=”#FFFFFF”>
<form method=”post” action=”<? echo($PHP_SELF) ?>”>
Your E-mail:
<input type=”text” name=”fromEmail” size=”25″>
Your Name: <input type=”text” name=”fromName” size=”25″>
Your Message:
<textarea cols=”50″ rows=”5″ name=”nMessage”>Your Message Here…</textarea>
Now to break apart the PHP code:
$Subject = “Test E-mail”;
$toEmail = “yourEmail@somewhere.com”;
These are variables for your e-mails subject and your target recipient’s e-mail. This is generally where you put your e-mail address if you are the one that is going to be receiving the e-mail
if(submit)
{
mail($fromEmail, $Subject, $nMessage.“\nFrom: “.$fromName.“<”.$fromEmail.“>”);
}
This is an if statement that checks to see if the submit button has been pressed. If yes, then it executes the script inside the brackets.
The mail() function on the inside is what sends the e-mail to you.
The mail function works like this:
mail ( string to, string subject, string message).
Enjoy your summer,
June 21st, 2008 at 3:41 pm
Bon article,
Avec des articles de geek comme ça, tu pourrais devenir un vrai gourou des NTIC au pays!
Surtout quand tu vas traiter d’aspects plus complexes de PHP, ColdFusion, Ajax et d’autres technologies
June 23rd, 2008 at 7:41 am
merci