If you want to use PHP to send mail, you can use the PHP built-in mail () function, but the mail () function requires server support must have its own mail server, if the use of the STMP service to send the message is equivalent to send instead of others, rather than from their own server, so not appropriate.
Then there is the characteristics of the mail () function itself, the mail () function is not perfect, can only send text e-mail, the message sent using the mail () is not authenticated, many messages are not received by the mail () function sent by the message or sent directly into the spam mailbox.
If you want to use an existing email account (such as a 126 email account) in your PHP program, you can use the Phpmailer class.
I test using 126 e-mail account, using 126 of the STMP service to send mail, the following steps:
1. Log in to your own mailbox and open the POP3/SMTP service in the settings.
When you turn on the service, you need to set the authorization code, which is the password for future use of the SMTP service.
2. Download Phpmailer, create a new test file, and introduce the class.phpmailer.php under the Phpmailer folder in the file.
include ("./phpmailer/class.phpmailer.php");
3. Create Phpmailer object on this page write the following code, where the * * * is filled out according to its own circumstances.
$mail=NewPhpmailer ();$mail->ISSMTP ();//Enable smtp//$mail->smtpdebug=1;//Open Debug mode//$mail->smtpsecure = "SSL";$mail->charset= ' Utf-8 ';//Set message encoding format$mail->host= "smtp.126.com;";//the name of the SMTP server (this is the case with 126 mailboxes)$mail->smtpauth =true;//Enable SMTP authentication$mail->username = "* * * * *";//your mailbox name can not write @ suffix, can also write$mail->password = "* * * * *";//mailbox Password, now open mailbox SMTP is called security Code$mail->port=25;//SMTP port number//$mail->port = 994;$mail->setfrom ("****@126.com", "Alvin");//Sender address (that is, your email address) and sender name$mail->addaddress ("* * * * @qq. com", "");//recipient address and name$mail-WordWrap= 100;//set character length per line$mail->ishtml (true);//whether HTML-formatted messages$mail->subject = "Hello this is the test";//Message Subject$mail->body = "Send you a message";//message content//$mail->altbody = "This is a plain text body in a non-profit HTML email client";//message body does not support alternate display of HTMLVar_dump($mail->send ());//Send method, send successful return true, failed to return False//echo $mail->errorinfo;//Get error message
4. Fill in the appropriate data, run the page, you can send a successful
Send mail using Phpmailer