Phpmailer Message class _php instances using Smtp.163.com to send mail methods

Source: Internet
Author: User
Tags word wrap
First step: Need to download Phpmailer package phpmailer-1.73.tar.gz from the Open source community: http://phpmailer.sourceforge.net/
Step two: Confirm that your server system already supports sockets such as, through Phpinfo (); see if support sockets
If this is not the case, note that the socket is part of the PHP extension and must be given a configuration option for./configure--enable-sockets at compile time.

The third step: Extract the files to your Web server directory, call the class can be, description: First include class.phpmailer.php, then create the object, set parameters, call member functions. See the sample code below for details:
Copy CodeThe code is as follows:
/*******************************
* 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 need to add @ domain name
$mail->password = "MailPassword"; SMTP Password

$mail->from = "yourmail@cgsir.com"; Sender Mailbox
$mail->fromname = "cgsir.com 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@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 = '




Welcome to Http://www.cgsir.com.


Thank you for registering as a member of this site!




';

$mail->altbody = "text/html";
if (! $mail->send ())
{
echo "Mail sent incorrectly

";
echo "Message error message:". $mail->errorinfo;
Exit
}
else {
echo "$user _name Mail sent successfully!
";
}
}

Parameter description (Sent to, message 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"; 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 an HTML-formatted message, remember to also specify

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

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