The example in this article describes how the PHP mailer class invokes a remote SMTP server to send mail implementations. Share to everyone for your reference, specific as follows:
PHP Mailer is a very useful PHP email Send class module, you can invoke the local SMTP send e-mail, you can call the remote SMTP send e-mail, but you need to pay attention to the use of some things, otherwise it will cause a failure to send, or simply can not call the situation, This article on the use of this class, I encountered problems and solutions to carry out, briefly explain the usage of PHP Mailer, and precautions.
First download the Phpmailer class library file, download here, just a resource points. Download Address: http://www.jb51.net/codes/27188.html
After downloading, place this file, or class.phpmailer.php, in a directory of your project, where you need to send the message:
<?php require ' class.phpmailer.php ';
try {$mail = new Phpmailer (true); $body = file_get_contents (' contents.html '); The contents of the message are written to the contents.html page $body = preg_replace ('//////', ', ', $body); Strip backslashes $mail->issmtp (); Tell the class to use SMTP $mail->smtpauth = true; Enable SMTP authentication $mail->port = 25; Set the SMTP server port $mail->host = "mail.yourdomain.com"; Remote SMTP server $mail->username = "yourname@yourdomain.com"; The user name on the remote SMTP server $mail->password = "YourPassword"; Your remote SMTP server on the user's corresponding password//$mail->issendmail (); Tell this class to use the SendMail component, and if you don't sendmail it when you use it, there will be $mail->addreplyto ("yourname@yourdomain.com", "the" "
);
$mail->from = "fromname@yourdomain.com";
$mail->fromname = "The Last";
$to = "toname@domain.com";
$mail->addaddress ($to);
$mail->subject = "Phpmailer message"; $mail->altbody = "To view", compatible email viewer! with an HTML; Optional, comment out and test $mail->wordwrap = 80;
Set word wrap $mail->msghtml ($body); $mail->ishtml (TRUE);
Send As HTML $mail->send ();
Echo ' message has been sent. ';
The catch (Phpmailerexception $e) {echo $e->errormessage ();}?>
Note: The above $mail->issendmail (); Need to comment out, otherwise, if there is no sendmail components, will prompt "Could not execute:/var/qmail/bin/sendmail" error !
More about PHP Interested readers can view the site topics: "PHP for XML file Operation skills Summary", "PHP date and Time usage summary", "PHP object-oriented Program Design Primer", "PHP string (String) Usage Summary", "php+ MySQL Database operations Introduction tutorial and PHP Common database operation Skills Summary
I hope this article will help you with the PHP program design.