Well a lot of people keep asking about PHP mail forms. I don’t have Flash on this computer, so I’m just going to have to make everyone stick with a regular HTML form. I will give the code and then explain that code…Here is how I do it:
<?
//------------------------------------------------
// File: 'phpmail.php'
// Func: using mail();
//------------------------------------------------
$Subject = "Test E-mail";
$toEmail = "[email protected]";
if($submit)
{
mail($fromEmail, $Subject, $nMessage."
From: ".$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"> <br>
Your Name: <input type="text" name="fromName" size="25"> <br>
Your Message: <br>
<textarea cols="50" rows="5" name="nMessage">Your Message Here...</text> <br>
<input type="submit" value="Submit">
</body>
</head>
ok, now to break apart the code… We’ll start with the HTML code. Everyone here should know this stuff, but if not, then here is a quick refresher…
<form method="post" action="<? echo($PHP_SELF) ?>">
**This piece defines the form’s action and method. Method is either “post” or “get”. The action is the path to the PHP file you are using. In this case, since we are using the same file, you use “echo($PHP_SELF)” to echo this page’s name. **
<input type="text" name="fromEmail" size="25">
Simple input field with the variable name “fromEmail”.
<input type="text" name="fromName" size="25">
Same thing. Simple input field with variable name “fromName”.
<textarea cols="50" rows="5" name="nMessage">Your Message Here...</text>
Textbox area with variable name "nMessage"
<input type="submit" value="Submit">
Creates the submit button
For more on HTML check out the links in this thread: Click Here!
[SIZE=3]Ok, now the PHP part of the code:[/SIZE]
$Subject = "Test E-mail";
$toEmail = "[email protected]";
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 recieving the e-mail
if(submit)
{
mail($fromEmail, $Subject, $nMessage."
From: ".$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)
Thats pretty self explanitory… To, Subject, and Message…
Thats it. Any questions?
Oh yeah, make sure that the file has a .php extension. you can name it whatever you like (ie. “emailform.php”), but it must have a .php extension.