How to implement online mail in PHP

Source: Internet
Author: User
Tags php book
When the application is visiting the Web page, sometimes want to Email to the Webmaster but then perform the e-mail program is always not to make, the application in the press mailto: abc@webjx.com to take a while to open your own Outlook here is not troublesome. At this time, it would be cool if the Homepage can provide the function of writing a letter. At the same time, the mailbox should be prompted or requested to be entered by the application.

When the application is visiting the Web page, sometimes want to Email to the Webmaster but then perform the e-mail program is always not to make, the application in the press mailto: abc@webjx.com to take a while to open your own Outlook here is not troublesome. At this time, it would be cool if the Homepage can provide the function of writing a letter. At the same time, the opinion mailbox still prompts or requests the application to fill in the materials, which is the best way to understand the customer for material warehousing.
All View mailboxes are like Outlook or other email software, enabling the function of sending new emails. The difference lies in that when Outlook is applied, the sender is fixed, and the recipient's address must be filled; in the opinion mailbox on the website, almost all the recipients are Webmasters. Instead, they need to fill in the sender's email address. Of course, another difference is that Outlook processes messages, and the view Mailbox is used by the Web server to process emails sent by the application.

After a more advanced design, it can even become a Web Mail, like HotMail. as long as you use a browser, you can use any computer to send and receive letters anywhere.

Of course, you can also do advanced design, store the opinions of the application in the material library, and leave the materials to be more useful in the future. However, this is not part of the discussion in this section.

In UNIX systems, most email-related titles are related to sendmail, and other systems are used unless the system administrator is paranoid. Therefore, the design and development of the view Mailbox is also the application of sendmail to achieve the desired effect. In the WindowsNT system, because there is no sendmail program, you need to purchase it separately, or use other mail delivery software. Therefore, this program cannot be executed in the WindowsNT system.

The procedure of the program is as follows:

Send the form to the browser of the application.
The application fills out the materials and sends them to the server.
The server clears the materials entered by the application and stores them in the file.
Use UNIX pipeline commands and sendmail programs to send views to system administrators.
The comments of the server notification application have been sent.
The following is a complete model program.


 
 
View mailbox 
 
 

$ Mailto = 'yourname @ webjx.com ';
If ($ topic! = '') And ($ Email! = '') And ($ body! = '')){
$ Tmpfilename = tempnam ('/tmp', 'DM ');
$ Fp = fopen ($ tmpfilename, 'w ');
Fwrite ($ fp, 'From: '. $ Email.' \ n ');
Fwrite ($ fp, 'Subject: '. $ topic .' <访客来信> \ N \ n ');
Fwrite ($ fp, $ body. '\ n \ n ');
Fwrite ($ fp, 'courier: '. $ sender.' \ n ');
Fwrite ($ fp, 'mail 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 'the letter has been sent !! Our staff will handle your title as soon as possible






';
} Else {
?>
 
}
?>
 


When processing analysis in PHP, the program first determines whether the application is filled with materials. If there is no material, the opinion form will be sent to the application. if there is material, the application will have input the relevant materials.

The processing principle is to first write the materials entered by the application into the temporary archive. however, to prevent multiple users from entering their opinions at the same time, the archive will be shrouded, therefore, different temporary archives need to be created each time. this title can be resolved by using the tempnam () function to create a unique temporary file without any errors. After the title of the file name is processed, the archive processing function provided by PHP is used to write the materials filled in by the application into the archive created before the application is completed. The archive process is initially completed. Even if the materials are not mailed out, the system can still keep the files in mind. It is worth noting that, if stored in/tmp, some UNIX systems (such as SUN Solaris) will lose these materials when the system is restarted, but some won't (such as Slackware Linux). In this regard, you may have to plan it first. if you want to retain it, you need to have a directory that will not be cleared.

The most powerful function in UNIX is the pipeline, which can be used to process the Mail action, as shown below:

Cat tmpfilename │/usr/lib/sendmail webjx@webjx.com

This command means to send the file to another sendmail program in the pipeline, and sendmail sends the file to the wilson@webjx.com. Therefore, the instructions in this pipeline can be used to send opinions to the Webmaster or customer service staff. To send messages to multiple users, you can use the mailing list or use the pipeline instructions sent several times.

To apply UNIX programs or external commands in PHP programs, you can apply the exec () function. After the mail is sent, the user is notified that the application is processing the mail, and the preliminary work of opinion processing is completed. Of course, how to deal with it later is not discussed in the PHP book.

Of course, there are more than one method to deliver messages. you can use mail () to send messages, or use a UNIX network socket. The so-called tricks will change for everyone.

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.