Phpmailer PHP Mail Sending class

Source: Internet
Author: User
Tags word wrap

I. Introduction of Phpmailer

Phpmailer is a powerful PHP mail-sending class that makes it easier to send messages, send attachments and HTML-formatted messages, and use an SMTP server to send messages.

Because the PHP comes with the Mail () function is not perfect, can only send text e-mail, and the mail () function can only be applied to the Linux server, there is one of the biggest problem is that the mail () function sent by the message is not authenticated, many messages do not receive the use of mail () The message sent by the function or the message sent directly into the spam mailbox. And Phpmailer gives us all the way to send mail, we can choose the appropriate method of mail processing as needed.

Phpmailer is a powerful message class with its main functional features:

Digital signatures that support message S/MIME encryption

Support mail multiple TOs, CCs, BCCs and Reply-tos

Can work on any server platform, so don't worry about the win platform can't send mail the problem

Supports text/html format messages

Image images can be embedded

Support for HTML reading is not supported for mail clients

Powerful debug function for sending mail

Custom Mail Header

Redundant SMTP server support

Supports 8bit, base64, binary, and quoted-printable codes

Word Wrap

Support multi-attachment sending function

Support for SMTP server Authentication feature

Tested successfully on SendMail, QMail, Postfix, Gmail, Imail, and Exchange platforms

The download file provided includes a detailed description of the documentation and sample instructions, so don't worry about the difficulty of getting started!

Phpmailer is very small, simple, convenient and fast

Second, the use of Phpmailer

1. First, download Phpmailer

http://code.google.com/a/apache-extras.org/p/phpmailer/

2. Unzip

Remove class.phpmailer.php and class.smtp.php into your project's folder

3. Create a function to send the message, where you need to configure the SMTP server

function Postmail ($to, $subject = ', $body = ') {
Author:jiucool website:http://www.jiucool.com
$to represents the recipient address $subject represents the message header $body represents the message body
Error_reporting (E_all);
Error_reporting (e_strict);
Date_default_timezone_set (' Asia/shanghai ');//Set time zone East eight zone
Require_once (' class.phpmailer.php ');
Include (' class.smtp.php ');
$mail = new Phpmailer (); New a Phpmailer object.
$body = Eregi_replace ("[]", "', $body); Filtering the content of the message as necessary
$mail->charset = "GBK";//Set the message encoding, default iso-8859-1, if the Chinese language must be set, otherwise garbled
$mail->issmtp (); Setting up using the SMTP service
$mail->smtpdebug = 1; Enabling the SMTP debugging feature
1 = errors and messages
2 = messages Only
$mail->smtpauth = true; Enable the SMTP authentication feature
$mail->smtpsecure = "SSL"; Security protocols that can be commented out
$mail->host = ' stmp.163.com '; SMTP Server
$mail->port = 25; Port number of the SMTP server
$mail->username = ' wangliang_198x '; SMTP server user name, PS: I'm messing around.
$mail->password = ' Password '; SMTP server password
$mail->setfrom (' xxx@xxx.xxx ', ' who ');
$mail->addreplyto (' xxx@xxx.xxx ', ' who ');
$mail->subject = $subject;
$mail->altbody = ' To view the message, please use an HTML compatible email viewer! '; Optional, comment out and test
$mail->msghtml ($body);
$address = $to;
$mail->addaddress ($address, ');
$mail->addattachment ("Images/phpmailer.gif"); Attachment
$mail->addattachment ("Images/phpmailer_mini.gif"); Attachment
if (! $mail->send ()) {
Echo ' Mailer Error: '. $mail->errorinfo;
} else {
echo "Message sent! Congratulations, Mail sent successfully! ";
}
}

4. Using functions

Postmail (' scutephp@qq.com ', ' My subject ', ' PHP build Station portal ');

Third, Phpmailer detailed instructions for use

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--Methods
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 ("xiaoxiaoxiaoyu@xiaoxiaoyu.cn", "Xiaoxiaoyu"), but parameter 2 is optional, addaddress (xiaoxiaoxiaoyu@xiaoxiaoyu.cn) is also possible.
Function prototype: Public function addaddress ($address, $name = ") {}

addattachment--Methods
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--Methods
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--Methods
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--Methods
Originating from: Phpmailer:: Addreplyto ()
Files: class.phpmailer.php
Note: Add a reply label, such as "reply-to"
Parameter 1 address, parameter 2 name
Function prototype: Public function Addreplyto ($address, $name = ") {}

Addstringattachment-Methods
Originating from: Phpmailer:: Addstringattachment ()
Files: class.phpmailer.php
Description: Add a string or binary attachment (Adds a string or binary attachment (Non-filesystem) to the list. )
Parameters: string, file name [, encoding, type]
Function prototype: Public function addstringattachment ($string, $filename, $encoding = ' base64 ', $type = ' Application/octet-stream ') { }

Authenticate--Methods
Derived from: Smtp::authenticate ()
Files: class.smtp.php
Description: Start SMTP authentication, must be called after Hello (), if authentication succeeds, returns True,
Parameter 1 user name, parameter 2 password
Function prototype: Public function Authenticate ($username, $password) {}

b Start

$Body--Properties
Derived from: Phpmailer:: $Body
Files: class.phpmailer.php
Description: Message content, HTML or text format

C Start

$CharSet--Properties
Derived from: Phpmailer:: $CharSet
Files: class.phpmailer.php
Description: Message encoding, default = Iso-8859-1

$ConfirmReadingTo--Properties
Derived from: Phpmailer:: $ConfirmReadingTo file class.phpmailer.php
Description: Receipt?

$ContentType--Properties
Derived from: Phpmailer:: $ContentType
Files: class.phpmailer.php
Description: Type of document, default to "Text/plain"

$CRLF--Properties
Derived from: Phpmailer:: $ContentType
Files: class.phpmailer.php
Description: The delimiter for SMTP reply end (SMTP reply line ending? )

class.phpmailer.php--Object
Originating From: class.phpmailer.php
Files: class.phpmailer.php
Description: Phpmailer Object

class.smtp.php--Object
Derived from: class.smtp.php file: class.smtp.php
Description: The SMTP Feature Object

clearaddresses--Methods
Derived from: phpmailer::clearaddresses ()
Files: class.phpmailer.php
Note: Clear the recipient to prepare for the next shipment. return type is void

clearallrecipients--Methods
Derived from: phpmailer::clearallrecipients ()
Files: class.phpmailer.php
Description: Clear all recipients, including CC (CC) and Bcc (secret send)

clearattachments--Methods
Derived from: phpmailer::clearattachments ()
Files: class.phpmailer.php
Description: Clear Attachment

Clearbccs--Methods
Derived from: Phpmailer::clearbccs () file class.phpmailer.php
Description: Clear Bcc (Secret send)

clearcustomheaders--Methods
Derived from: Phpmailer::clearcustomheaders ()
Files: class.phpmailer.php
Description: Clear the custom header

Clearreplytos--Methods
Derived from: Phpmailer::clearreplytos ()
Files: class.phpmailer.php
Explanation: Clear Reply person

Close--method
Derived from: Smtp::close ()
Files: class.smtp.php
Description: Close an SMTP connection

Connect--method
Derived from: Smtp::connect ()
Files: class.smtp.php
Description: Establish an SMTP connection [/color]mailer.html

$ContentType--Properties
Derived from: Phpmailer:: $ContentType
Files: class.phpmailer.php
Description: Type of document, default to "Text/plain"

D Start

$do _debug--Properties
Originating from: SMTP:: $do _DEBUG
Files: class.smtp.php
Description: SMTP Debug output

Data-method
Originating from: SMTP::D ata ()
Files: class.smtp.php
Description: Sends a data command and message information to the server (Sendsthemsg_datatotheserver)

E start

$Encoding--Properties
Derived from: Phpmailer:: $Encoding
Files: class.phpmailer.php
Description: Set the encoding method of the message, Optional: "8bit", "7bit", "binary", "base64", and "quoted-printable".

$ErrorInfo--Properties
Derived from: Phpmailer:: $ErrorInfo
Files: class.phpmailer.php
Description: Returns the last error message in Mail SMTP

Expand--Methods
Derived from: Smtp::expand ()
Files: class.smtp.php
Description: Returns all users in the mailing list. Succeeds returns the array, otherwise returns False (Expandtakesthenameandaskstheservertolistallthepeoplewhoaremembersofthe_list_. Expandwillreturnbackandarrayoftheresultorfalseifanerroroccurs.)

F Start:

$From--Properties
Derived from: Phpmailer:: $From file class.phpmailer.php
Description: Sender e-mail address

$FromName--Properties
Derived from: Phpmailer:: $FromName
Files: class.phpmailer.php
Description: Sender Salutation

H Start:

$Helo--Properties
Derived from: Phpmailer:: $Helo
Files: class.phpmailer.php
Description: Set Smtphelo, Default is $hostname (Setsthesmtpheloofthemessage (defaultis$hostname).)

$Host--Properties
Derived from: Phpmailer:: $Host
Files: class.phpmailer.php
Description: Set the SMTP server in the format: hostname [port number], such as smtp1.example.com:25 and smtp2.example.com are legal

$Hostname--Properties
Derived from: Phpmailer:: $Hostname
Files: class.phpmailer.php
Description: Set the hostname in Message-id and andreceivedheaders and be used at the same time by $helo. If blank, the default is server_name or ' localhost.localdomain '

Hello--method
Derived from: Smtp::hello ()
Files: class.smtp.php
Description: Send the HELO command to the SMTP server

Help--method
Derived from: Smtp::help ()
Files: class.smtp.php
Description: If there are keywords, get help information for keywords

I begin with:

IsError--Methods
Derived from: Phpmailer::iserror ()
Files: class.phpmailer.php
Description: Returns whether an error occurred

ishtml--Methods
Derived from: phpmailer::ishtml ()
Files: class.phpmailer.php
Description: Sets whether the letter is in HTML format

IsMail--Methods
Derived from: Phpmailer::ismail ()
Files: class.phpmailer.php
Description: Set whether to use PHP's mail function to send a piece

Isqmail--Methods
Derived from: Phpmailer::isqmail ()
Files: class.phpmailer.php
Description: Set whether to use Qmailmta to send a piece

Issendmail--Methods
Derived from: Phpmailer::issendmail ()
Files: class.phpmailer.php
Description: Whether to use the $sendmail program to send a piece

ISSMTP--Methods
Derived from: Phpmailer::issmtp ()
Files: class.phpmailer.php
Description: Whether to send a piece using SMTP

M Start:

$Mailer--Properties
Derived from: Phpmailer:: $Mailer
Files: class.phpmailer.php
Description: Sender mode, ("Mail", "SendMail", or "SMTP"). One of the

Mail--method
Derived from: Smtp::mail ()
Files: class.smtp.php
Description: Returns TRUE or false, starting with a mail address in $from. If true, the sender is started

N begins with:

Noop--Methods
Derived from: Smtp::noop ()
Files: class.smtp.php
Description: Send an NOOP command to the SMTP server

P begins with:

$Password--Properties
Derived from: Phpmailer:: $Password
Files: class.phpmailer.php
Description: Set the password for SMTP

$PluginDir--Properties
Derived from: Phpmailer:: $PluginDir
Files: class.phpmailer.php
Description: Set Phpmailer plug-in directory, only valid in Smtpclass not in Phpmailer directory

$Port--Properties
Derived from: Phpmailer:: $Port
Files: class.phpmailer.php
Description: Set the port number for SMTP

$Priority--Properties
Derived from: Phpmailer:: $Priority
Files: class.phpmailer.php
Note: Set the message delivery priority level. 1= Emergency, 3 = normal, 5 = not urgent

Phpmailer--Object
Originating From: Phpmailer
Files: class.phpmailer.php
Description: Phpmailer-phpemailtransportclass

Q Start

Quit--method
Derived from: Smtp::quit ()
Files: class.smtp.php
Description: Sends a QUIT command to the server if no error occurs. So turn off sock, or $close_on_error to True

R start

Recipient--Methods
Derived from: Smtp::recipient ()
Files: class.smtp.php
Description: Use to send the RCPT command to SMTP with the parameters: $to

Reset--method
Derived from: Smtp::reset ()
Files: class.smtp.php
Description: Sends the RSET command to cancel processing in transit. Success returns TRUE, otherwise false

S start:

$Sender--Properties
Derived from: Phpmailer:: $Sender
Files: class.phpmailer.php
Description: Setsthesenderemail (Return-path) ofthemessage. Ifnotempty,willbesentvia-ftosendmailoras ' Mailfrom ' Insmtpmode.

$Sendmail--Properties
Derived from: Phpmailer:: $Sendmail
Files: class.phpmailer.php
Description: Set the directory for the sender program

$SMTPAuth--Properties
Derived from: Phpmailer:: $SMTPAuth
Files: class.phpmailer.php
Description: Set whether SMTP requires authentication, use username and password variables

$SMTPDebug--Properties
Derived from: Phpmailer:: $SMTPDebug
Files: class.phpmailer.php
Description: Set SMTP to debug output?

$SMTPKeepAlive--Properties
Derived from: Phpmailer:: $SMTPKeepAlive
Files: class.phpmailer.php
Note: Do not close the connection after each sender. If true, you must use Smtpclose () to close the connection

$SMTP _port--Properties
Originating from: SMTP:: $SMTP _port
Files: class.smtp.php
Description: Set the SMTP port

$Subject--Properties
Derived from: Phpmailer:: $Subject
Files: class.phpmailer.php
Description: Set the subject of the letter

Send--method
Derived from: Smtp::send ()
Files: class.smtp.php
Note: Start a message transfer from the specified e-mail address

Send--method
Derived from: Phpmailer::send ()
Files: class.phpmailer.php
Description: Create a message and develop a sender program. Returns False if the sender is unsuccessful, use ErrorInfo to view the error message

Sendandmail--Methods
Derived from: Smtp::sendandmail ()
Files: class.smtp.php
Note: Start a message transfer from the specified e-mail address

Sendormail--Methods
Derived from: Smtp::sendormail ()
Files: class.smtp.php
Note: Start a message transfer from the specified e-mail address

SetLanguage--Methods
Derived from: Phpmailer::setlanguage ()
Files: class.phpmailer.php
Description: Sets the language type of the Phpmailer error message, returns False if the language file cannot be loaded, and defaults to 中文版

SMTP--method
Derived from: Smtp::smtp ()
Files: class.smtp.php
Description: Initialize an object so that the data is in a known state

SMTP--Object
Originating From: SMTP
Files: class.smtp.php
Description: SMTP Object

Smtpclose--Methods
Derived from: Phpmailer::smtpclose ()
Files: class.phpmailer.php
Description: If there is an active SMTP, close it.

T start

$Timeout--Properties
Derived from: Phpmailer:: $Timeout
Files: class.phpmailer.php
Description: Set the timeout (in seconds) for the SMTP server. Note: This property is not valid under Win32

Turn--Methods
Derived from: Smtp::turn ()
Files: class.smtp.php
Description: This is an optional SMTP parameter, currently Phpmailer does not support him and may support future

U start

$Username--Properties
Derived from: Phpmailer:: $Username
Files: class.phpmailer.php
Description: Set the SMTP user name

V Start

$Version--Properties
Derived from: Phpmailer:: $Version
Files: class.phpmailer.php
Description: Returns the version of Phpmailer

Verify--Methods
Derived from: smtp::verify ()
Files: class.smtp.php
Description: Checks whether the user name has been verified by the server

W Start:

$WordWrap--Properties
Derived from: Phpmailer:: $WordWrap
File: class.phpmailer.php Description: Sets the maximum number of characters per line, and wraps the line after the number of changes

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.