Now you can send emails from your web sites with full control over design
style and functionality. PHP is the way to go for online email form.
Here is how to get started.
Step 1: Create E-Mail Form
Here is a sample html email form
<form action="" method="post">
Name: <br>
<input type="text" name="name">
<br>
Email: <br>
<input type="text" name="email">
<br>
Subject: <br>
<input type="text" name="subject">
<br>
Text:<br>
<textarea name="message" cols="" rows=""></textarea><br>
<input type="submit" name="submit" value="Send">
<input type="reset" name="Reset" value="Reset">
</form>
Copy the html code above and past it into a file with the name contactus.php
Now its time to add the php code.
Step 2: Sending the data
We will first check to see if the form was submitted then we will check
to see if all fields were filled in. If all is well, we well send each form data to it's perspective variables (indicated
by the sign "$") and send out the email with a successful message.
If all field were not filled-in, then display an error message. The php code
is below.
<?php
if ($submit) { // if the form was sent do the
following
if($name && $subject
&& $email && $message ) { // if
all fields were filled-in send email
mail("you@youraddress.com","$subject","$message","From:
$name <$email>") or die("email error");
echo "Message Sent"; // if all went
well, display message was sent
} else {
echo "All fields must be filled in!<BR>"; //
if not all were filled in, display error message
}
} // end php submission code
?>
Now just copy and past the php code above into the "contactus.php"
file. You can place it anywhere inside the body tag and it will work just fine.
Be sure to check for the next PHP Advanced Email Form coming soon to NewSourceMedia.com
.
Amazon.com has a variety of book on PHP Click
here to see the list of PHP books available.
NewSourceMedia is providing links to these listings as
a courtesy, and makes no representations regarding the content or
any information related thereto. Any questions, complaints or claims
regarding the downloaded content or details must be directed to the appropriate
publisher. We do not encourage or condone the use of any
software in violation of applicable laws.
Comments
Dan The Man
05.07.2007
Saint Tosin's advice works. Just remember to leave the form's method as POST, but remove the reference of where it needs to post to. (I left it in and it took me fives mins to work out why it wasn't working!)
Appart from that it worked like a dream, and stops me having to have loads of different mailform.pl and mailform.cgi files lying around when all I need is a simple form2mail application.
Uswege Mwaipyana
04.11.2006
Chad
10.09.2005
woah@lala.com
09.24.2005
Alex
03.09.2005
Durk
03.09.2005
Alex
01.07.2005
If they will not help you try using one of the Host companies listed on this page on the top right under Partners to help support my site. Thanks.
archeens
01.07.2005
email error <<<<<<< plz help me !
Alex
01.03.2005
Saint Tosin
01.02.2005
You have a page named send.php where your form is, all you have to do is include a hidden field in the form with the name 'send' and set value to 'ok'.
Then on the page you specified in d action part of the form,simply add the line 'if ($send=="ok") instead of using if($submit) to initialize your execution.
check this
page name = text.php
[? // code to test if variable sent
if ($send=="ok") {
// do codes here;
}
else {
// i want to use the same form page to process
// the content of the form below so that if the
// the form is empty it will show the form and
// if submitted, it will do d job and hide d form
?}
[form action=test.php method=post enctype=xxx]
input type=hidden name=send value="ok"]
[input type=text name=wotever size=41 value=""]
[input type=submit name="submit" value="Submit"]
[/form]
[?
}
// end of all these...
?]
John, this wil help you out if u try it this way.
Alex
11.21.2004
Second - For a second php page to show the sent status, just copy and past the php code above into a second file called message.php. Go back and change the html form code by adding the page name inside of the form action like (action="message.php").
John
11.21.2004
Furthermore I also get a problem with the $submit variable when testing it on my local server PHP VER 4.3.6 Running on IIS 5.. However when I upload it to the remote server it runs fine without throwing out a variable error message...........Any thoughts on this????
Have you any sample code you might be able to pots for the messagesent.php page like you suggest............. I'm currently living in Venezuela and English Books are difficult to come by and expensive............
I buy from Amazon about every 3 months and only when I can justify the shipping costs............ so I'm a little stuck for the time being................
Thanks again for the excellent tutorial and not as complicated as some of the others on the site............. and for making it available for free too! ;-) Hope you can help with the confirm code.........
Alex
11.21.2004
Second thing - this is a working sample email form using PHP. It works just fine as one page. You don't need a second message.php page. However, you can use the code and add-on more functions as you wish. Like extracting the php code to a second page call messagesent.php, but make sure your form is pointing to it when it is submitted.
There are some more email solutions below.
John
11.20.2004
John
11.20.2004
If so have you got the code that will do this??? Thyanks
John
11.19.2004
As we're not using DB Server Behaviors for this type of form I am wondering how to get round this............ Have you any suggestions as to a script........... like on post refresh.update..and return a page saying message sent????
Saint Tosin
10.20.2004
eg.
and replace the if ($submit) with if ($sendme == "ok")
this will shut the $submit error up for eternity.
Alan Berman
10.15.2004
@import_request_variables(\"P\");
BEFORE the if($submit) line.
Grace
10.07.2004
seems that the problem lies with the page unable to recognise the "$submit" value...HOW???
Alex
10.07.2004
Grace
10.07.2004
Copied the e-mail form;
pasted the php codings into the body section;
Error Message on Display page:
"Notice: Undefined variable: submit in D:\singaporejobsinteractive\contact.php on line 23"
and line 23 is:
"if ($submit) { // if the form was sent do the following"
Alex
09.16.2004
$message = "Product = $Product n\Price =$Price \n$message";
Brian
09.16.2004
Whenever I tried to add a new field in the form / new variable in the php, I get an "email error" message. How do you go about adding new fields & variables to be displayed in the e-mail I receive? Thanks so much!
Alex
09.15.2004
Here is the sample code:
<input name="submit" type="hidden" value="submit">
<input name="button" type="image" id="button" value="send" src="images.gif">
Cate
09.15.2004
This is the code I used for the image button:
<input name="sumbit" type="image" value="send" src="images/submit.gif">
Why does this make a difference?
AussieClint
09.11.2004
No I will just work on the validation of the various fields and I am away.
Thanks heaps.
Erik Ginnerskov
09.11.2004
I have checked, that all input names matches the variables in the script.
Yours
Erik Ginnerskov
Lee
09.06.2004
I'm using a host with PHP 4.3.8.
It still refuses to work.
Alex
09.06.2004
• Email address is correct
• Spam is not blocking your address or message
• File saved as .php
• Field names match variable names
• You have PHP on your web server!!!
Lee
09.05.2004
I'm not receiving the e-mail.
Though it says "Message sent".
If it was being picked up by the spam filter, the message
would most likely go into the spam folder.
Any ideas?
Alex
08.26.2004
nick
08.26.2004
The requested method POST is not allowed for the URL /test/contactus.html.
is it my server setup?
Running Apache 1.3.27
Alex
08.22.2004
Brian
08.21.2004
Alex
08.17.2004
Alex
08.17.2004
This will also sent a copy of info to the person who submited the form.
You can edite the "Message Sent" to fit your own needs.
Sir_diko
08.17.2004
Frontin'
05.20.2004
Alex
04.29.2004
Alex
04.28.2004
- Thanks
amy
04.27.2004
What I want to do is similar to what eg. Cnn.com does...it allows you to send an article to a friend...but instead I want to send an html email. Is this possible?
NexGc
04.26.2004
NexGc
04.26.2004
Alex
04.25.2004
NexGc
04.25.2004
PHP Notice: Undefined variable: submit in w:\inetpub\wwwroot\test1.php on line 2
stellagan
04.15.2004
Mark
03.29.2004
Alex
03.08.2004
the PHP first two lines of code to the following:
if ($submit) { // if the form was sent do the following
if($email != $email2)
echo "Emails do not match!";
elseif($name && $subject && $email && $message ) {
Philippe
03.08.2004
Thank you
Philippe
Alex
02.21.2004
EPiK
02.19.2004