Using SMTP to send mail in PHP
Today, a friend asked me how to send a message in PHP , so I let him go to Baidu Google a lot of search. After a long while I asked him to solve the problem, he was very frustrated that the online tutorials are a template, according to their coming there will be some problems, so I tidied up, ready to re-summarize this method, so as to stay for future reference.
?
?
1. What is SMTP
the full name of SMTP is simple ? Mail? Transfer? Protocol, that is,Simple Mail Transfer Protocol, simple to understand, this thing is to send mail, as to how specifically to achieve, there is no need to delve into, because I only need it this function.
?
?
2. use the appropriate software to implement SMTP
I chose hmailserver, personally feel this software is good, specific download address can come here to find
Find the latest version
Http://www.hmailserver.com/index.php?page=download
?
?
3. Configure hmailserver
The software is good, as for the installation that is all-in-one, installed after the login, focusing on the configuration of this piece.
?
?
?
First, see if the service in Status is started, and then proceed to the next step.
?
?
?
Then find Domain, select the Add on the right border
?
?
?
?
Next, select the General tab and write the domain name you want, such as I use benzlee.com. Here is a misunderstanding, many people ask, here should not fill in 163.com or sina.com or tom.com these mailboxes? At this point, many tutorials are misleading - I am now using my own computer as a server to send mail, why write their domain name? Of course I can customize my favorite domain name, with what 163.com what sina.com completely have no relationship.
?
?
?
?
Then, check the tab Limits, set the data as shown, here is a few restrictions on the size of the sending message, can be adjusted according to their own needs
?
?
?
?
Next, it's time to create your own mail account, which means you use that account as the message. Select Accounts under benzlee.com and click Addto add your own account information
?
?
?
?
In the General tab Address Write the account name you want, such as I set to Benzlee, enter your own password, I default to empty (this password is arbitrary, unless you want to authenticate the account), set maximum?size? to be + , so the account is created.
?
?
?
?
Then, select setting->protocolsto Remove the front of the IMAP check .
?
?
?
Next, select SMTP, switch to the delivery?of?e-mail tab, and set it according to the diagram.
?
?
?
Then, select advanced->auto-ban, and remove the checkmark from the front of the Enabled
?
?
?
?
Then switch to IP? Ranges 's My? Computer, make the following settings
?
?
?
?
Finally, switch to the Internet and make the following settings
?
?
?
?
Done,hmailserver configuration is complete. Go to Next step
?
4. Modify The contents of the php.ini as follows:
? 1) Modify smtp?=?localhost
2) Modify [email protected], here pay special attention to remove the preceding semicolon, otherwise the sentence is considered to be commented. This sentence refers to the e -mail is sent out by WHO,[email protected] is just the mail account of their own configuration.
3) Do not forget to restart Apacheafter the modification, otherwise there will be no effect.
?
5. Write a mail.php Program yourself, you can use the following code:
?
$content? =? " This?is?a?mail?from?benzlee ";??????? here is the message content
$content =?wordwrap ($content);????? //? if a row is greater than? A . characters, using? WordWrap ()
Mail ("[email protected]", "this?" Is? My? SMTP ", $content);???? call PHP 's own mail function, the first parameter is the sending object, the second is the message header, and the third is the message content.
?>
?
[Email protected] is the email address you want to send mail, you can change to your usual mailbox for verification.
?
6. finally call this written php file can send the mail, is done.
did not receive himself e-mail? Don't tangle, go to the Junk mail box and see what you know.
At last. Reprint please specify the source, the truth you understand.