A simple automatic mail delivery system (i)

Source: Internet
Author: User
Tags html form mail variables php3 file
A simple automated email messaging system
Another powerful feature of PHP is that he has the ability to modify variables through HTML forms, and through these variables we can accomplish many tasks, including sending wed-based messages, outputting the information to the screen, and reading and passing data from the database. Let's build a small automated email system to demonstrate this capability.
Let's assume that there is such an HTML form:

--------------------------------------

<HTML>
<HEAD>
<title>request for more information</title>
<BODY>

<center>would more information about we company?
<P>

<table WIDTH = 400><tr><td align = right>

<form action= "email.php3" method= "POST" >

Your name:<br>
<input type= "text" name= "NAME" size= "maxlength=" >
<P>
Your Email address:<br>
<input type= "text" name= "email" size= "maxlength=" >
<P>
I prefer:
<select name= "Preference" >
<option value = Apples>apples
<option value = Oranges>oranges
</SELECT>
<P>
<input type= "Submit" value= "Send it!" >
</FORM>
</TD></TR></TABLE></CENTER>

</BODY>
</HTML>

--------------------------------------

Save this file as a moreinfo.html

Note that the action points to the file: Email.php3 below is the Email.php3 file:

--------------------------------------

?
/* This script would handle the variables passed from the moreinfo.html file */
PRINT "<CENTER>"; PRINT "Hello, $name." PRINT "<BR><BR>";
PRINT "Thank for your interest.<br><br>";
PRINT "We'll send information to $email, and have noted is $preference.";
PRINT "</CENTER>";
?>

--------------------------------------

Save the above file as a email.php3

When the user types their name and email in the form, click on "Send it! button, the form calls the Email.php3 file, which appears as follows: (here we assume that person ' name is bill, email address is bgates@devshed.com, apples selected):

--------------------------------------
Hello, Bill.

Thank for your interest.

We'll send information to bgates@devshed.com, and have noted so you like Apples

--------------------------------------

So our project has not been completed, because we do not know who has inserted some information, there is no substantive things have happened, we have no way to write a letter to bill.

To reduce the burden of sending standard emails manually, we can use the PHP mail () command.
Syntax: void mail (string to, string subject, String message, string add_headers);

to---Send out e-mail to the specified mailing address
subject Represents a theme
message for the contents of the letter
additional_headers can be omitted to represent the headers of other mail files.

Thus, if we insert this command into the print statement, we can automatically send a letter to the user and the owner of the site, letting us know who needs the information.

--------------------------------------

?
Mail ("$email", "Your Request for Information", "$namen
Thank for your interest!nwe sell fresh corn
Place your in http://www.buycorn.com,
and receive a FREE package of $preference! ");
Mail ("administration@buycorn.com",
"Visitor Request for info.", "$name requested for INFORMATION.N
The email address is $email. n the visitor prefers $preference. ");
?>

--------------------------------------

Note: the Mail () function is only available on the SendMail server, so in most cases, it is OK to use it before using it.

But when a lot of people fill in the information, as managers, you can not one by one browse the letter, you could use the database to track how many people choose apples, how many people choose oranges? There are many kinds of databases like this, and one of the fastest is MySQL.

In the next article, I'll show you how to combine PHP with MySQL.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.