Compile CGI for SendMaild

Source: Internet
Author: User
Article Title: write CGI about SendMaild. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
On a UNIX host, we can easily send emails through programming. sometimes we need to sort the data from the form and send it to a mailbox, such as a visitor's message and apply online.
  
In UNIX systems, there is usually a sendmail program used to send emails. this is a very complicated EMAIL system, but it is very easy to use it in CGI Programming to send emails, the specific operation is to open a channel and input the output information as the sendmail program.
  
The code is as follows:
  
Open (MAIL, "|/usr/sbin/sendsendmail zjxyz@XXXX.XXX"); # note the space print MAIL $ msg close MAIL;
  
In this way, we can send the content in the variable $ msg to the mailbox whose address is zjxyz@XXXX.XXX through the sendmail program on the server. Note that this is just a simple example, some details need to be discussed. In the above procedures, the mail recipient will receive a letter with no title and no reply address. to send a letter with a decent appearance, you must send the mail header before sending the content: see the following example:
  
Open (MAIL, "|/usr/sbin/sendsendmail zjxyz@XXXX.XXX ");
Print MAIL "To: $ toemailn ";
Print MAIL "From: $ fromemailn ";
Print MAIL "Reply-to: $ fromemailn ";
Print MAIL "Subject: $ subjectn ";
PrintMAIL $ msg;
Print MAIL "nn ";
Close MAIL;
  
We can see that "To:", "From:", "Reply-to:", and "Subject:" are used To identify the header, they are not treated as the body of the letter in the Mail program, and the line break symbol in the program is required.
  
I have to raise a security question here. sometimes the address we send is obtained from the form. if we do not strictly check the validity of the EMAIL address obtained from the form, it will lead to attacks by malicious attackers and cause your CGI program to execute operations that damage the system. The consequences are very serious. An example is as follows:
  
If ($ FORM {'mailto'} = ~ /(.*)@(.*)/){
.....
.....
.....
}
Related Article

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.