Phpmailer Sending HTML content, message instances with attachments _php Tutorial

Source: Internet
Author: User
Phpmailer is a packaged PHP mail sending class, support for sending HTML content of e-mail, and can add attachments to send, not like the php itself mail () function requires server environment support, you only need to set up the mail server with relevant information to achieve the mail delivery function.
This article will combine the example code to explain how to set up and implement the sending HTML and the mail with attachments.

First, you can go to Phpmailer to get the latest download package and extract it to the Web directory.
Then create a sendmail.php file, load the Phpmailer class, and set the relevant property parameters, such as mail server address, sender and recipient, message content, etc., please see the code:
Copy CodeThe code is as follows:
Require_once (' class.phpmailer.php '); Load Phpmailer class

$mail = new Phpmailer (); Instantiation of
$mail->issmtp (); Enable SMTP
$mail->host = "smtp.163.com"; SMTP server with 163 mailboxes as an example
$mail->port = 25; Mail Send port
$mail->smtpauth = true; Enable SMTP authentication

$mail->charset = "UTF-8"; Character
$mail->encoding = "base64"; Encoding method

$mail->username = "helloweba@163.com"; Your e-mail
$mail->password = "xxx"; Your password.
$mail->subject = "Hello"; Message header

$mail->from = "helloweba@163.com"; Sender address (that is, your mailbox)
$mail->fromname = "Moonlight Light"; Sender's name

$address = "xyz@163.com";//Recipient Email
$mail->addaddress ($address, "Pro");//Add Recipient (address, nickname)

$mail->addattachment (' Xx.xls ', ' my attachments. xls '); Add an attachment and specify a name
$mail->ishtml (TRUE); Support HTML format content
$mail->addembeddedimage ("logo.jpg", "My-attach", "logo.jpg"); Set up a picture in a message
$mail->body = ' Hello,Friends!
This is an e-mail from target= "_blank" >jb51.net!

'; Message body Content

Send
if (! $mail->send ()) {
echo "Mailer Error:". $mail->errorinfo;
} else {
echo "Message sent!";
}
As can be seen from the code, after instantiating Phpmailer, we specify that SMTP is used to send mail, set up an SMTP mail server, and enable SMTP authentication, if your mail server does not require authentication, set $mail->smtpauth=false, And you don't need a password to send it. Then set the character set and encoding support Chinese characters, note that the original Phpmailer package has less than ideal support for Chinese characters, so you can download the improvements package in the Helloweba sample. Then set the sender and recipient to add attachments. Note the attachment is best not in Chinese, you can specify the Chinese name in AddAttachment (). Then set the message HTML content, the last is sent, the process at a glance,
If the send is successful, you will receive the following message:

http://www.bkjia.com/PHPjc/824691.html www.bkjia.com true http://www.bkjia.com/PHPjc/824691.html techarticle Phpmailer is a packaged PHP mail sending class, support for sending HTML content of e-mail, and can add attachments to send, not like the php itself mail () function requires server environment support, ...

  • 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.