Detailed introduction to Phpmailer and how to use _php tips

Source: Internet
Author: User
Keywords Phpmailer
Tags format message word wrap
For the use of Phpmailer, a friend who needs to refer to the following

First, you need to download the Phpmailer file package Phpmailer
Second, confirm that your server system already supports socket, through phpinfo (), check whether sockets is supported (socket is part of PHP extension), if it appears as "enabled", it is supported.
Third, unzip the file into your Web server directory and call the class.
First contains the class.phpmailer.php, then creates the object, sets the parameters, and invokes the member function.

Example 1, making a function convenient to call

The code is as follows:

<?php require ("phpmailer/class.phpmailer.php");            function Smtp_mail ($sendto _email, $subject, $body, $extra _hdrs, $user _name) {$mail = new Phpmailer ();                  $mail->issmtp ();   Send via SMTP $mail->host = "200.162.244.66";           SMTP servers $mail->smtpauth = true;     Turn on SMTP authentication $mail->username = "Yourmail"; SMTP username Note: Normal mail authentication does not need to add @ domain name $mail->password = "MailPassword";      SMTP password $mail->from = "yourmail@yourdomain.com";  Sender mailbox $mail->fromname = "Administrator";   Sender $mail->charset = "GB2312";            Specify the character set here!            $mail->encoding = "base64";  $mail->addaddress ($sendto _email, "username");            Recipient's mailbox and name $mail->addreplyto ("yourmail@yourdomain.com", "yourdomain.com"); $mail->wordwrap = 50; Set word wrap word wrapping//$mail->addattachment ("/vaR/tmp/file.tar.gz ");            Attachment Accessories//$mail->addattachment ("/tmp/image.jpg", "new.jpg");  $mail->ishtml (TRUE);            Send As HTML//message subject $mail->subject = $subject; Message content $mail->body = "

Note:

1. The character set of the message, $mail->charset = "GB2312";//Specify the character set here! Here I only specify as GB2312 because so Outlook can display the subject of the message normally, I tried to set it to utf-8 but the garbled characters appear under Outlook.
2. If you are sending HTML-formatted messages, remember to also specify
3. If you want to use it for mass mailing, remember to modify the Include file function, such as:
Require ("phpmailer/class.phpmailer.php");
Change to
require_once ("phpmailer/class.phpmailer.php");
Otherwise, a redefinition of the class is generated.

Personally think to use Phpmailer, first, need to have a mail server, PHP mail function is not specified, should be using the PHP settings of SMTP.

You need to specify it here, and you need to specify the manager and password for the mail server.

Phpmailer is also a powerful message class

phpmailer main features:

support mail S/MIME encrypted digital signature
Support mail multiple TOs, CCs, BCCs and Reply-tos
can work on any server platform, so there's no need to worry about the win platform being unable to send mail
support text/html format message
can embed image Image
Support for mail clients that do not support HTML reading
Powerful send mail debug feature debug
Custom message header
Redundant SMTP server support
Support 8bit, base64, Binary, and Quoted-printable encoding
Text wrapping
supports multi-attachment forwarding
support for SMTP server Authentication
in SendMail, QMail, Postfix, Gmail, Imail, Exchange and other platform testing Try to successfully
the download file provided, including detailed documentation and sample instructions, so do not worry about difficult to use problems!
Phpmailer is very small, simple, convenient, fast
The above information from Jiucool translation from Phpmailer official website, reproduced please specify! The use of

Phpmailer (Here is an example of using Gmail SMTP to send mail, and, of course, SendMail POPs):
First to http://www.php.cn/download the latest version of the package
after the download is complete, Find class.phpmailer.php, class.smtp.php two classes and put them in your own directory!
then create a new PHP file named here: phpmail_jiucool.php
phpmail_jiucool.php content as follows:
I write the mail-sending module directly into a function postmail_jiucool_com () , you can call the function directly when you use it, the function content is:

The code is as follows:

function postmail_jiucool_com ($to, $subject = "", $body = "") {//author:jiucool website:http://www.php.cn///$to represents the recipient address $ Subject indicates that 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 comes out $body = eregi_replace ("[\]" "," ', $body); The content of the message is necessary to filter $mail->charset = "UTF-8";//Set the message encoding, the default iso-8859-1, if the text must be set in Chinese, otherwise garbled $mail->issmtp (); Set $mail->smtpdebug = 1 using the SMTP service; Enable the SMTP debugging feature//1 = errors and messages//2 = messages only $mail->smtpauth = true; Enable the SMTP authentication feature $mail->smtpsecure = "SSL"; Security protocol $mail->host = "smtp.googlemail.com"; SMTP server $mail->port = 465; The port number of the SMTP server $mail->username = "SMTP Server user name"; SMTP Server user name $mail->password = "SMTP server password"; SMTP server password $mail->setfrom (' sender address, such as admin#jiucool.com #换成 @ ', ' sender name '); $mail->addreplyto ("Mail reply address, such as admin#jiucool.com #换成 @", "Mail reply person's name"); $Mail->subject = $subject; $mail->altbody = "To view the message, please use an HTML compatible email viewer! -From www.jiucool.com "; Optional, comment out and test $mail->msghtml ($body); $address = $to; $mail->addaddress ($address, "Recipient name"); $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, the Mail was sent successfully! "; } }
  • 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.