Examples of learning PHP comments Mailbox Chapter

Source: Internet
Author: User
Tags comments log mail php book

When users visit the Web site, sometimes want to email to webmaster but then execute the email program always does not make, the user presses the mailto:abc@abc.abc.tw also spend a period of time to open their own here Outlook not trouble. At this point, it would be cool if homepage could provide the function of writing letters. At the same time, the opinion of the mailbox or to remind users to be sure to fill in what data, which for data warehousing, is also the best way to understand customers.
The entire comment box is actually like Outlook or other e-mail software, open the function of sending new mail, the difference is in the use of Outlook, the sender is fixed, and to fill in the address of the recipient, and the comments on the website, the recipient is almost webmaster, Instead, you have to fill in the sender's e-mail address. The other difference, of course, is that Outlook handles letters, and the mailbox is handled by the WEB server by the user.

After a more advanced design, you can even become a Web mail, like HotMail, where you can send and receive letters from any computer anywhere with a browser.

Of course, the advanced design can also be done to store the user's opinions in the database for later collation into more useful information. But this is not part of the discussion.

In UNIX systems, most e-mail-related problems are related to SendMail, unless the system administrator is more paranoid and uses other systems. Therefore, the opinion box design and development, but also the use of sendmail to achieve the required functions. In the WindowsNT system, this program cannot be executed in the WindowsNT system because there is no SendMail program, which requires a fee to purchase, or use other mail delivery software.

The process of the program is as follows

Send out the form to fill out the comments on the user's browser.
The user fills in and sends out the data to the server.
The server stores the user's data and deposits it in the file.
Use UNIX piping directives and sendmail programs to give advice to system administrators.
The server notifies the user that comments have been sent out.
Here is the complete sample program


<title> Comments Box </title>
<body>
<?php

$mailto = "yourname@hahaha.com.tw";

if ($topic!= "") and ($Email!= "") and ($body!= "")) {
$tmpfilename = Tempnam ("/tmp", "DM");
$fp = fopen ($tmpfilename, "w");

Fwrite ($FP, "from:". $Email. " \ n ");
Fwrite ($FP, "Subject:" $topic. "< visitor letter >\n\n");
Fwrite ($FP, $body. " \ n ');
Fwrite ($fp, "Messenger:" $sender. " \ n ");
Fwrite ($fp, "Letter IP:". $REMOTE _addr. " \ n ");
Fclose ($FP);

$execstr = "Cat". $tmpfilename. "│/usr/lib/sendmail". $mailto;
EXEC ($EXECSTR);

$EXECSTR = "echo $sender $REMOTE _host >>/var/log/mail.log";
EXEC ($EXECSTR);
echo "Letter has been sent out!! The site staff to deal with your problem as soon as possible <p><br><br><br><br><br> ";
} else {
?>
<form action=<? Echo ($GLOBALS ["php_self"]);?> method=post>
<table border=0>
<tr><td> theme </td><td><input Type=text size=20 name=topic></tr>
<tr><td> name </td><td><input type=text size=20 name=sender></tr>
<tr><td>email</td><td><input Type=text size=20 name=email></tr>
&LT;TR&GT;&LT;TD colspan=2> content <br><textarea cols=26 rows=10 name=body></textarea></td> </tr>
&LT;TR&GT;&LT;TD colspan=2><div align=right><input type=submit value= "Send out" ></td></tr>
</table>
</form>
?
}
?>
</body>


In the process of parsing in PHP, the program first determines whether the user fills in the data. If there is no information, send out the opinion form to the user, if the information indicates that the user has entered the relevant information, then the processing.

The principle of processing is to first write the user information into the staging file, however, to prevent multiple users from filling in the comments at the same time, the file will be overwritten, so each time a different temporary archive, this issue can be used Tempnam () function to solve, to create a unique temporary file. After the file name problem is processed, the file processing function provided by PHP is used to write the user's information to the file that has been established. Closing the file is done initially. Even if the information is not mailed, the system can still save the opinion file. It is noteworthy that if stored in/tmp, some UNIX systems (such as SUN Solaris) will lose the data when restarting the system, while others will not (such as Slackware Linux), which may have to be planned and saved in a directory that will not be erased.

The strongest feature in UNIX is the pipeline, which can be used to handle the action of a letter, as follows

Cat Tmpfilename│/usr/lib/sendmail wilson@biglobe.net.tw

The meaning of this instruction is to send the file to the SendMail program on the other end of the pipeline, and SendMail to send the file to wilson@biglobe.net.tw. Therefore, this piping instruction can be used to send comments to webmaster or customer service department personnel. To send to more than one person, you can use the mailing list or a few more times to mail the pipe instructions.

You can use the EXEC () function to use a UNIX program or an external instruction in a PHP program. After the letter is sent, the user is already in the process of handling the preliminary work of the comments. Of course, how to deal with it, is not a PHP book can be discussed.

Of course, there are more than one way to send a letter, you can use mail () function to send letters, but also the use of UNIX network socket to do, the so-called play legal person will change, ingenious each have different.



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.