This is to use the open-source project PHPMailer to implement mail sending. first download the file. here I download the version 5.1, and then put the three classes. ***. put the php file under the project file. I first used gmail, but failed. The problem was that the authentication failed. later I used QQ mail and sent it successfully.
- Require ("class. phpmailer. php"); // the downloaded file must be in the directory where the file is located.
- $ Mail = new PHPMailer (); // Create a mail sending class
- $ Address = "youbinliu@126.com ";
- $ Mail-> IsSMTP (); // send using SMTP
- $ Mail-> Host = "smtp.qq.com"; // your enterprise Post Office domain name
- $ Mail-> SMTPAuth = true; // enable SMTP verification
- $ Mail-> Username = "843831601@qq.com"; // Post Office Username (enter the complete email address)
- $ Mail-> Password = "************"; // Post Office Password
- $ Mail-> Port = 25;
- $ Mail-> From = "843831601@qq.com"; // email address of the sender
- $ Mail-> FromName = "liuyoubin ";
- $ Mail-> AddAddress ("$ address", "a"); // The recipient address, which can be replaced with any email address to receive the email, the format is AddAddress ("recipient email", "recipient name ")
- // $ Mail-> AddReplyTo ("","");
- // $ Mail-> AddAttachment ("/var/tmp/file.tar.gz"); // add an attachment
- // $ Mail-> IsHTML (true); // set email format to HTML // whether HTML format is used
- $ Mail-> Subject = "PHPMailer test mail"; // mail title
- $ Mail-> Body = "Hello, this is the test mail"; // The mail content
- $ Mail-> AltBody = "This is the body in plain text for non-HTML mail clients"; // additional information, which can be omitted
- If (! $ Mail-> Send ())
- {
- Echo "failed to send the email.
";
- Echo "error cause:". $ mail-> ErrorInfo;
- Exit;
- }
- Echo "email sent successfully ";
- /*************************************** **********
- Attachment:
- Phpmailer (simplified version)
- Start with:
- $ AltBody -- attribute
- From: PHPMailer ::$ AltBody
- File: class. phpmailer. php
- Note: the setting of this attribute is that HTML standby display is not supported in the mail body.
- AddAddress -- method
- From: PHPMailer: AddAddress (), File: class. phpmailer. php
- Note: Add recipients. Parameter 1 is the recipient's mailbox, and parameter 2 is the recipient's name. Example AddAddress ("eb163@eb163.com", "eb163"), but parameter 2 is optional, AddAddress (eb163@eb163.com) is also possible.
- Function prototype: public function AddAddress ($ address, $ name = ''){}
- AddAttachment -- method
- From: PHPMailer: AddAttachment ()
- File: class. phpmailer. php.
- Note: add attachments.
- Parameter: Path, name, encoding, type. The path is required, and the others are optional.
- Function prototype:
- AddAttachment ($ path, $ name = '', $ encoding = 'base64', $ type = 'application/octet-stream '){}
- AddBCC -- method
- From: PHPMailer: AddBCC ()
- File: class. phpmailer. php
- Note: add a BCC. For the differences between CC and BCC, see [differences between BCC and CC in SMTP sending].
- Parameter 1 is the address and parameter 2 is the name. Note that this method only supports SMTP in win32 and does not support the mail function.
- Function prototype: public function AddBCC ($ address, $ name = ''){}
- AddCC -- method
- From: PHPMailer: AddCC ()
- File: class. phpmailer. php
- Note: add a CC. For the differences between CC and BCC, see [differences between BCC and CC in SMTP sending].
- Parameter 1 is the address and parameter 2 is the name. Note that this method only supports SMTP in win32 and does not support the mail function.
- Function prototype: public function AddCC ($ address, $ name = ''){}
- AddCustomHeader -- method
- From: PHPMailer: AddCustomHeader ()
- File: class. phpmailer. php
- Note: add a custom email header.
- The parameter is the header information.
- Function prototype: public function AddCustomHeader ($ custom_header ){}
- AddEmbeddedImage -- method
- From: PHPMailer: AddEmbeddedImage ()
- File: class. phpmailer. php
- Add an embedded image.
- Parameter: Path, return handle [, name, encoding, type]
- Function prototype: public function AddEmbeddedImage ($ path, $ cid, $ name = '', $ encoding = 'base64', $ type = 'application/octet-stream '){}
- Tip: AddEmbeddedImage (PICTURE_PATH. "index_01.jpg", "img_01", "index_01.jpg ");
- Reference in html
- AddReplyTo -- method
- From: PHPMailer: AddRepl
- **************************************** *********/
- ?>
|