A script that sends a E-MAIL may be one of the most common scripts you can find on the Web site, although it is very simple, a Mail script can sometimes make programmers very frustrated. in PHP, there is a function called mail (). it only needs to know the recipient's address and the sender of the email to send the email, but requires mail () to press SyntaxHighlighter. all
A script that sends a E-MAIL may be one of the most common scripts you can find on the Web site, although it is very simple, a Mail script can sometimes make programmers very frustrated. in PHP, there is a function called mail (). it only needs to know the recipient's address and the sender of the email to send the email, but requires mail () you still need to solve some difficult problems to run as you want. to enable mail () to run, you must have an SMTP server so that PHP can connect to it. no matter how important the server is to the Mail program, most people do not have a single star concept about how it operates. in this tutorial, we will reveal SMTP secrets and solve some common problems of sending emails using PHP. another topic in this article will include the method of traversing an address list cyclically and sending an email to the recipient in both text and HTML formats. SMTP is short for Simple Mail Transfer Protocol, and an SMTP server is a computer that runs this Protocol and sends emails. running this protocol actually refers to running Such as Sendmail and Qmail programs-if you are using a non-Windows computer. on the Windows platform, as part of the Windows NT Service Pack or the SMTP Service program built in Windows 2000 is a typical program. i'm not saying that SMTP packages only have those, but they are the most common. if your Web site uses part of the Internet Service provider's host package, the SMTP Service program should have been installed on this computer. if you are a system administrator of an ISP or indoor computer, you may have installed some SMTP software on this computer to process emails sent from the Web server. however, if you are a personal user and only one developer Web service is running on your PC, you may not have run the SMTP software on your machine. below is a non- A simple but accurate thumb rule: if you are a Windows user and never see the word "SMTP server", then you have not run this program. if you do not have one, you have two options: install, configure, and maintain an SMTP Service program. (if you do not know what it is, you are not recommended to use this method) or use an existing SMTP server. "If a server is not running now, how can I use it? "You may want to ask. if your computer is connected to the Internet through a dial-up connection (or DSL or cable), you can use your ISP's external mail server. for example, if you use a Windows 98 system and use a 56 kbps modem to connect to the Internet through EarthLink, you can use mail.earthlink.net as your SMTP server. no matter what kind of Mail client you use for your external Mail server (Eudora, Outlook, Netscape Mail, etc.), they will be the same as the process of using your PHP code to use your SMTP server. the trick is to let PHP know a little truth. in php. in the ini management configuration file, several entries need to be set so that the mail () function can run normally. before changing them, you can figure out what they are. you can use the phpinfo () function to create a file to display the current configuration of the system. this file includes: Save the file, place it in the root directory of the file of your Web service program, and then access it through your browser. you should be able to see a beautifully formatted information that shows your configuration. the entry you want to view is as follows: SMTP sendmail_from sendmail_path if you are not using windows, the sendmail_path command is the only thing you need to worry about. if you are using Windows, you need to check the last two commands. if you are using Linux or a Unix variant, sendmail_path should look like this: sendmail_path =/usr/sbin/sendmail or if you use Qmail: sendmail_path =/var/qmail/bin/sendmail in this command, you can also set configuration parameters to specify the queue buffer options or display the set Return-Path header, as shown below: sendmail_path =/usr/sbin/sendmail-t-fyou@yourdomain.com as a non-Windows user, that's all you have to do. if you are using Windows, you have more things to do. you also need to take a look at the values of SMTP and sendmail_from. do not confuse sendmail in the sendmail_from command name. although you have not used a program named Sendmail on Windows, it is only the command name. don't be scared by it. in the result displayed in your phpinfo (), check the default values of SMTP and sendmail_from-they are either blank or contain random values. you should change them to meaningful values. if you are determined to run an SMTP service program on this computer, you are in php. the entries in the INI file should be as follows: SMTP = localhost. However, if you want to use the external email server of your ISP (EarthLink in this example), php. emails in ini should look like the following: SMTP = mail.earthlink.net you can also use IP addresses instead of domain names, because computers do not distinguish these two entries. the second configuration command is sendmail_from, which should be set to the email address in the From header. it can be modified in the script but is usually used as the default value. the following is a sample youraddress@yourdomain.com for this configuration directive referring to your own mail address. sendmail_from = after the youraddress@yourdomain.com makes these configuration changes, restart the Web service program and use the phpinfo () function to verify the changes. after these tasks are completed, you can use PHP to send emails.