PHPmailer下载与说明以及样例

来源:互联网 发布:仙界网络直播间 编辑:程序博客网 时间:2024/04/30 21:14

https://github.com/Synchro/PHPMailer# 下载地址

http://phpmailer.worxware.com/index.php?pg=methods 方法说明

Updated for PHPMailer v5.0.0

Methods (v5.0.0)TypeDefaultDescriptionset($name, $value)string $name
string $value Method provides ability for user to create own custom pseudo-properties (like X-Headers, for example). Example use:
$mail->set('X-MSMail-Priority', 'Normal');addCustomHeader($value)string $value Method provides ability for user to create own custom headers (like X-Priority, for example). Example use:
$mail->addCustomHeader("X-Priority: 3");MsgHTML($message)  Evaluates the message and returns modifications for inline images and backgrounds. Sets the IsHTML() method to true, initializes AltBody() to either a text version of the message or default text.IsMail()booleantrueSets Mailer to send message using PHP mail() function. (true, false or blank)IsSMTP()boolean Sets Mailer to send message using SMTP. If set to true, other options are also available. (true, false or blank)IsSendmail()boolean Sets Mailer to send message using the Sendmail program. (true, false or blank)IsQmail()boolean Sets Mailer to send message using the qmail MTA. (true, false or blank)SetFrom($address, $name = "")string $address
string $name Adds a "From" address.AddAddress($address, $name = "")string $address
string $name Adds a "To" address.AddCC($address, $name = "")string $address
string $name Adds a "Cc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.AddBCC($address, $name = "")string $address
string $name Adds a "Bcc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.AddReplyTo($address, $name = "")string $address
string $name Adds a "Reply-to" address.Send()  Creates message and assigns Mailer. If the message is not sent successfully then it returns false. Use the ErrorInfo variable to view description of the error. Returns true on success, false on failure.AddAttachment($path, $name = "", $encoding = "base64",
    $type = "application/octet-stream")string $path
string $name
string $encoding
string $type Adds an attachment from a path on the filesystem. Returns false if the file could not be found or accessed.AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64",
    $type = "application/octet-stream")string $path
string $cid
string $name
string $encoding
string $type Adds an embedded attachment. This can include images, sounds, and just about any other document. Make sure to set the $type to an image type. For JPEG images use "image/jpeg" and for GIF images use "image/gif". If you use the MsgHTML() method, there is no need to use AddEmbeddedImage() method.ClearAddresses()  Clears all recipients assigned in the TO array. Returns void.ClearCCs()  Clears all recipients assigned in the CC array. Returns void.ClearBCCs()  Clears all recipients assigned in the BCC array. Returns void.ClearReplyTos()  Clears all recipients assigned in the ReplyTo array. Returns void.ClearAllRecipients()  Clears all recipients assigned in the TO, CC and BCC array. Returns void.ClearAttachments()  Clears all previously set filesystem, string, and binary attachments. Returns void.ClearCustomHeaders()  Clears all custom headers. Returns void.

http://phpmailer.worxware.com/index.php?pg=properties 属性说明

Updated for PHPMailer v5.0.0

Property (v5.0.0)TypeDefaultDescription$Prioritypublic3Email priority (1 = High, 3 = Normal, 5 = low)$CharSetpubliciso-8859-1Sets the CharSet of the message$ContentTypepublictext/plainSets the Content-type of the message$Encodingpublic8bitSets the Encoding of the message. Options for this are "8bit", "7bit", "binary", "base64", and "quoted-printable"$ErrorInfopublic Holds the most recent mailer error message$Frompublicroot@localhostSets the From email address for the message$FromNamepublicRoot UserSets the From name of the message$Senderpublic Sets the Sender email (Return-Path) of the message. If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.$Subjectpublic Sets the Subject of the message.$Bodypublic Sets the Body of the message. This can be either an HTML or text body. If HTML then run IsHTML(true).$AltBodypublic Sets the text-only body of the message. This automatically sets the email to multipart/alternative. This body can be read by mail clients that do not have HTML email capability such as mutt. Clients that can read HTML will view the normal Body.$WordWrappublic0Sets word wrapping on the body of the message to a given number of characters$MailerpublicmailMethod to send mail: ("mail", "sendmail", or "smtp").$Sendmailpublic/usr/sbin/sendmailSets the path of the sendmail program.$PluginDirpublic Path to PHPMailer plugins. This is now only useful if the SMTP class is in a different directory than the PHP include path.$ConfirmReadingTopublic Sets the email address that a reading confirmation will be sent.$Hostnamepublic Sets the hostname to use in Message-Id and Received headers and as default HELO string. If empty, the value returned by SERVER_NAME is used or 'localhost.localdomain'.$HostpubliclocalhostSets the SMTP hosts. All hosts must be separated by a semicolon. You can also specify a different port for each host by using this format: [hostname:port] (e.g. "smtp1.example.com:25;smtp2.example.com"). Hosts will be tried in order.$Portpublic25Sets the default SMTP server port.$Helopublic Sets the SMTP HELO of the message (Default is $Hostname).$SMTPAuthpublicfalseSets SMTP authentication. Utilizes the Username and Password variables.$Usernamepublic Sets SMTP username.$Passwordpublic Sets SMTP password.$Timeoutpublic10Sets the SMTP server timeout in seconds. This function will not work with the win32 version.$SMTPDebugpublicfalseSets SMTP class debugging on or off.$SMTPKeepAlivepublicfalsePrevents the SMTP connection from being closed after each mail sending. If this is set to true then to close the connection requires an explicit call to SmtpClose().$SingleTopublicfalseProvides the ability to have the TO field process individual emails, instead of sending to entire TO addresses

来源:http://www.cnblogs.com/Liangw/archive/2013/01/30/2882579.html

利用PHPMailer 来完成PHP的邮件发送

<?phprequire 'PHPMailerAutoload.php';$mail = new PHPMailer;//$mail->SMTPDebug = 3;                               // Enable verbose debug output$mail->isSMTP();                                      // Set mailer to use SMTP$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers$mail->SMTPAuth = true;                               // Enable SMTP authentication$mail->Username = 'user@example.com';                 // SMTP username$mail->Password = 'secret';                           // SMTP password$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted$mail->Port = 587;                                    // TCP port to connect to$mail->From = 'from@example.com';$mail->FromName = 'Mailer';$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient$mail->addAddress('ellen@example.com');               // Name is optional$mail->addReplyTo('info@example.com', 'Information');$mail->addCC('cc@example.com');$mail->addBCC('bcc@example.com');$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name$mail->isHTML(true);                                  // Set email format to HTML$mail->Subject = 'Here is the subject';$mail->Body    = 'This is the HTML message body <b>in bold!</b>';$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';if(!$mail->send()) {    echo 'Message could not be sent.';    echo 'Mailer Error: ' . $mail->ErrorInfo;} else {    echo 'Message has been sent';}
0 0
原创粉丝点击