Phpmailer message classes use smtp.163.com to send mail methods _php instances

Source: Internet
Author: User
Tags require word wrap
Step one: Need to download Phpmailer packages phpmailer-1.73.tar.gz from the open source community: http://phpmailer.sourceforge.net/
Step two: Confirm that your server system has supported the socket as shown below, through phpinfo (); see if support for sockets
If you do not have this item, please note that the socket is part of the PHP extension and must be given a configuration option for the./configure--enable-sockets at compile time.

Step three: Unzip the file to your Web server directory, call the class on it: First include class.phpmailer.php, then create objects, set parameters, call member functions. For details, see the following sample code:
Copy Code code as follows:

<?php
/*******************************
* Author: Li Yingjiang
* Date: 2006-12-7
*******************************/
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 require @ domain name
$mail->password = "MailPassword"; SMTP Password

$mail->from = "yourmail@cgsir.com"; Sender's mailbox
$mail->fromname = "cgsir.com Administrator"; Sender

$mail->charset = "GB2312"; This specifies the character set!
$mail->encoding = "base64";

$mail->addaddress ($sendto _email, "username"); Recipient mailboxes and Names
$mail->addreplyto ("yourmail@cgsir.com", "cgsir.com");

$mail->wordwrap = 50; Set word Wrap
$mail->addattachment ("/var/tmp/file.tar.gz"); Attachment
$mail->addattachment ("/tmp/image.jpg", "new.jpg");
$mail->ishtml (TRUE); Send As HTML
Message subject
$mail->subject = $subject;
Message content
$mail->body = '
<meta http-equiv= "Content-language" content= "ZH-CN" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "><body>
Welcome to <a href= "http://www.cgsir.com" >http://www.cgsir.com</a> <br/><br/>
Thank you for registering as a member of this site! <br/><br/>
</body>
';

$mail->altbody = "text/html";
if (! $mail->send ())
{
echo "message sent incorrectly <p>";
echo "Message error message:". $mail->errorinfo;
Exit
}
else {
echo "$user _name Mail sent successfully!<br/>";
}
}

Parameter description (send to, mail subject, message content, additional information, user name)
Smtp_mail (' yourmail@cgsir.com ', ' Welcome to cgsir.com! ', ' NULL ', ' cgsir.com ', ' username ');

?>
What to note:
1. The character set of the message, $mail->charset = "GB2312"; This specifies the character set! I only specify GB2312 here because Outlook displays the subject of the message correctly, I tried to set it to Utf-8, but it appears garbled in Outlook.

2. If it is sent in HTML format mail, then remember also designated as <meta http-equiv= "Content-type" content= "text/html;" charset=gb2312 ">

3. If you want to use it for mass mailing, remember to modify the Include file function, such as:
Require ("phpmailer/class.phpmailer.php");
To
Require_once ("phpmailer/class.phpmailer.php");
Otherwise, a redefinition of the class is generated.

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.