This is to use open source project Phpmailer to achieve the mail, first download the file, I download it here is 5.1 version, and then put three class.***.php files into the project file, I first use is Gmail, but failed, the problem is authentication failure, later used QQ mailbox, send success.
- Require ("class.phpmailer.php"); The downloaded file must be placed in the directory where the file is located
- $mail = new Phpmailer (); Set up a mail sending class
- $address = "youbinliu@126.com";
- $mail->issmtp (); Send using SMTP mode
- $mail->host = "smtp.qq.com"; Your enterprise Post office domain name
- $mail->smtpauth = true; Enable the SMTP authentication feature
- $mail->username = "843831601@qq.com"; Post Office User name (please fill in the full email address)
- $mail->password = "***********"; Post Office password
- $mail->port=25;
- $mail->from = "843831601@qq.com"; Email Sender Email Address
- $mail->fromname = "Liuyoubin";
- $mail->addaddress ("$address", "a");//recipient address, can be replaced with any email message you want to receive, in the format 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 is used
- $mail->subject = "phpmailer test mail"; Message header
- $mail->body = "Hello, this is Test mail"; Message content
- $mail->altbody = "The body in plain text for non-html mail clients"; Additional information, you can omit
- if (! $mail->send ())
- {
- echo "message failed to send.
";
- echo "Error Reason:". $mail->errorinfo;
- Exit
- }
- echo "Mail sent successfully";
- /*************************************************
- Attachment:
- Phpmailer instructions for use in Chinese (simplified version)
- A begins with:
- $AltBody--Properties
- Derived from: Phpmailer:: $AltBody
- Files: class.phpmailer.php
- Description: The setting of this property is an alternate display of HTML that is not supported in the message body
- addaddress--method
- Derived from: phpmailer::addaddress (), File: class.phpmailer.php
- Note: Increase the recipient. Parameter 1 is the recipient's mailbox, and Parameter 2 is the recipient's salutation. 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
- Derived from: Phpmailer::addattachment ()
- File: class.phpmailer.php.
- Note: Add attachments.
- Parameters: Path, name, encoding, type. Where the path is required and the other is optional
- Function Prototypes:
- AddAttachment ($path, $name = ', $encoding = ' base64 ', $type = ' Application/octet-stream ') {}
- addbcc--method
- Derived from: PHPMAILER::ADDBCC ()
- Files: class.phpmailer.php
- Description: Add a secret send. For the difference between CC and BCC, see [the difference between BCC and CC in SMTP senders].
- The parameter 1 is the address, and the parameter 2 is the name. Note This method only supports the use of SMTP under Win32, and does not support the mail function
- Function prototype: Public function addbcc ($address, $name = ") {}
- ADDCC--Methods
- Derived from: PHPMAILER::ADDCC ()
- Files: class.phpmailer.php
- Note: Add a CC. For the difference between CC and BCC, see [the difference between BCC and CC in SMTP senders].
- Parameter 1 is address, parameter 2 is name note This method supports SMTP only with Win32, and does not support mail functions
- Function prototype: Public function ADDCC ($address, $name = ") {}
- addcustomheader--method
- Derived from: Phpmailer::addcustomheader ()
- Files: class.phpmailer.php
- Description: Add a custom e-mail header.
- parameter is header information
- Function prototype: Public function Addcustomheader ($custom _header) {}
- Addembeddedimage--Methods
- Derived from: Phpmailer::addembeddedimage ()
- Files: class.phpmailer.php
- Description: Add an embedded image
- Parameters: 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");
- Referencing in HTML
- addreplyto--method
- Originating from: Phpmailer:: Addrepl
- *************************************************/
- ?>
Copy Code
|