Phpmailer class calls the remote SMTP server to send mail implementation method, mailersmtp. Phpmailer class calls the remote SMTP server to send mail implementation method. mailersmtp this article describes the phpmailer Class Call remote SMTP server to send mail implementation method. I would like to share with you how to use the mailer class of php to call the remote SMTP server to send emails.
This example describes how to use the php mailer class to call the remote SMTP server to send emails. We will share this with you for your reference. The details are as follows:
Php mailer is a very useful php email sending module. it can call local smtp to send emails or remote smtp to send emails, however, you need to pay attention to some things during use. Otherwise, the sending may fail or cannot be called at all. This article describes the problems and solutions I encountered when using this class, briefly describe the usage and precautions of php mailer.
First, download the phpmailer class library file. here, you only need one resource point. : Http://www.bkjia.com/codes/27188.html
After downloading the file, put class. phpmailer. php in a directory of your project, and write the following content where you need to send an email:
<? Phprequire 'class. phpmailer. php '; try {$ mail = new PHPMailer (true); $ body = file_get_contents('contents.html '); // the content of the mail is written to the contents.html page with $ 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 $ ma Il-> Username = "yourname@yourdomain.com"; // Username $ mail-> Password = "yourpassword" on the remote SMTP server "; // the password of the user on your remote SMTP server // $ mail-> IsSendmail (); // tell this class to use the Sendmail component, note this out if there is no sendmail build in use, otherwise there will be $ mail-> AddReplyTo ("yourname@yourdomain.com", "First Last "); $ mail-> From = "fromname@yourdomain.com"; $ mail-> FromName = "First Last"; $ to = "toname@domain.com"; $ mail-> AddAddress ($ ); $ mail-> Subject = "Firs T PHPMailer Message "; $ mail-> AltBody =" To view the message, please use an HTML compatible email viewer! "; // 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. ';} catch (phpmailerException $ e) {echo $ e-> errorMessage () ;}?>
Note: The above $ mail-> IsSendmail (); needs to be commented out, otherwise, if there is no sendmail component, the prompt "cocould not execute: /var/qmail/bin/sendmail "error!