This is the use of open source project Phpmailer to achieve mail, first download files, I download here is 5.1 version, and then put three class.***.php files to the project file, I first use is Gmail, but failed, the problem is authentication failed, and later used the QQ mailbox, sent successfully.
Tags:Send mail
code fragment (1) [Full screen view all code]
1. [Code][php] code
02 |
Require ("class.phpmailer.php"); The downloaded file must be placed in the same directory as the file |
03 |
$mail = new Phpmailer (); Create a mail delivery class |
04 |
$address = "youbinliu@126.com"; |
05 |
$mail->issmtp (); Send using SMTP method |
06 |
$mail->host = "smtp.qq.com"; Your Business Post office domain name |
07 |
$mail->smtpauth = true; To enable the SMTP authentication feature |
08 |
$mail->username = "843831601@qq.com"; Post Office username (please fill in the full email address) |
09 |
$mail->password = "***********"; Post Office password |
11 |
$mail->from = "843831601@qq.com"; Mail Sender email Address |
12 |
$mail->fromname = "Liuyoubin"; |
13 |
$mail->addaddress ("$address", "a");//recipient address, can be replaced by any e-mail message that you want to receive mail, in the form of addaddress ("addressee Email", "Recipient Name") |
14 |
$mail->addreplyto ("", ""); |
16 |
$mail->addattachment ("/var/tmp/file.tar.gz"); Add attachment |
17 |
$mail->ishtml (TRUE); Set email format to HTML//whether to use HTML format |
19 |
$mail->subject = "phpmailer test mail"; Message headers |
20 |
$mail->body = "Hello, this is Test mail"; Message content |
21st |
$mail->altbody = "This are the body in plain text for non-html mail clients"; Additional information that can be omitted |
25 |
Echo message failed to send. <p> "; |
26 |
echo "Error Reason:". $mail->errorinfo; |
30 |
echo "Mail sent successfully"; |
33 |
/************************************************* |
36 |
Phpmailer Chinese usage instructions (simple version) |
39 |
Originated from: Phpmailer:: $AltBody |
40 |
File: class.phpmailer.php |
41 |
Description: This property is set to an alternate display that does not support HTML in the message body |
43 |
From: Phpmailer::addaddress (), File: class.phpmailer.php |
44 |
Description: 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. |
45 |
Function prototype: Public function addaddress ($address, $name = ' ") {} |
47 |
Derived from: Phpmailer::addattachment () |
48 |
File: class.phpmailer.php. |
49 |
Description: Add accessories. |
50 |
Parameters: Path, name, encoding, type. Where the path is required, others are optional |
52 |
AddAttachment ($path, $name = ', $encoding = ' base64 ', $type = ' Application/octet-stream ') {} |
54 |
Derived from: PHPMAILER::ADDBCC () |
55 |
File: class.phpmailer.php |
56 |
Description: Add a secret send. The difference between CC and BCC see [the difference between BCC and CC in SMTP senders]. |
57 |
Parameter 1 is the address, and parameter 2 is the name. Note This method only supports the use of SMTP under Win32, and does not support mail functions |
58 |
Function prototype: Public function addbcc ($address, $name = ' ") {} |
60 |
Derived from: PHPMAILER::ADDCC () |
61 |
File: class.phpmailer.php |
62 |
Description: Add a CC. The difference between CC and BCC see [the difference between BCC and CC in SMTP senders]. |
63 |
Parameter 1 is the address, parameter 2 is the name note This method only supports the use of SMTP under Win32, and does not support mail functions |
64 |
Function prototype: Public function ADDCC ($address, $name = ' ") {} |
65 |
addcustomheader--method |
66 |
Derived from: Phpmailer::addcustomheader () |
67 |
File: class.phpmailer.php |
68 |
Description: Add a custom email head. |
69 |
parameter is header information |
70 |
Function prototype: Public function Addcustomheader ($custom _header) {} |
71 |
Addembeddedimage--method |
72 |
Derived from: Phpmailer::addembeddedimage () |
73 |
File: class.phpmailer.php |
74 |
Description: Add an embedded picture |
75 |
Parameters: path, return handle [, Name, encoding, type] |
76 |
Function prototypes: Public function Addembeddedimage ($path, $cid, $name = ', $encoding = ' base64 ', $type = ' Application/octet-stream ') { } |
77 |
Hint: Addembeddedimage (picture_path. "Index_01.jpg", "img_01", "index_01.jpg"); |
80 |
Originated from: Phpmailer:: Addrepl |
81 |
*************************************************/ |