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 was 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 the message is sent in HTML format, then 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");
Change to
require_once ("phpmailer/class.phpmailer.php");
Otherwise, a redefinition of the class is generated.
http://www.bkjia.com/PHPjc/319386.html www.bkjia.com true http://www.bkjia.com/PHPjc/319386.html techarticle first step: Need to download Phpmailer package phpmailer-1.73.tar.gz from the Open source community: http://phpmailer.sourceforge.net/The second step: Confirm that your server system already supports sockets such as ...