Home > Backend Development > PHP Tutorial > The php mailer class calls the remote SMTP server to send emails, mailersmtp_PHP tutorial

The php mailer class calls the remote SMTP server to send emails, mailersmtp_PHP tutorial

WBOY
Release: 2016-07-12 08:57:54
Original
873 people have browsed it

The php mailer class calls the remote SMTP server to send emails, mailersmtp

This article describes the example of the php mailer class calling the remote SMTP server to send emails. Share it with everyone 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, and it can also call remote SMTP to send emails. However, you need to pay attention to some things when using it, otherwise it will cause In the case where the sending fails or cannot be called at all, this article will expand on the problems and solutions I encountered when using this class, and briefly explain the usage of php mailer and precautions.

First download the phpmailer class library file, download it here, only one resource point is needed. Download address: http://www.bkjia.com/codes/27188.html

After downloading, place this file, class.phpmailer.php, in a directory of your project, and write this where you need to send emails:

<&#63;php
require 'class.phpmailer.php';
try {
  $mail = new PHPMailer(true);
  $body = file_get_contents('contents.html'); //邮件的内容写到contents.html页面里了
  $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"; // 远程SMTP服务器
  $mail->Username = "yourname@yourdomain.com"; // 远程SMTP 服务器上的用户名
  $mail->Password  = "yourpassword"; // 你的远程SMTP 服务器上用户对应的密码
  //$mail->IsSendmail(); //告诉这个类使用Sendmail组件,使用的时候如果没有sendmail组建就要把这个注释掉,否则会有
  $mail->AddReplyTo("yourname@yourdomain.com","First Last");
  $mail->From    = "fromname@yourdomain.com";
  $mail->FromName  = "First Last";
  $to = "toname@domain.com";
  $mail->AddAddress($to);
  $mail->Subject = "First 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();
}
&#63;>

Copy after login

Note: The above $mail->IsSendmail(); needs to be commented out, otherwise if there is no sendmail component, the error "Could not execute: /var/qmail/bin/sendmail" will be prompted!

Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP XML file operation skills", "Summary of php date and time usage", "Introduction to php object-oriented programming tutorial", "php Summary of String Usage", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of PHP Common Database Operation Skills"

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • PHP uses phpmailer to send emails
  • thinkphp uses phpmailer to send emails
  • After phpmailer sends the email, return to the collection How to check whether the sender has read the email
  • Solution to the problem that phpmailer cannot send emails normally on the server
  • php sends emails in various forms (mail qmail mail system phpmailer class)
  • A simple way to use PHP to send emails using PHPMailer
  • Analysis of examples of using PHPMailer to send emails in php (example of 126.com)
  • PHPMailer usage tutorial (analysis of examples of sending emails with PHPMailer)
  • Use PHPMAILER to send emails instance application
  • PHPMailer mail class uses smtp.163.com to send emails

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1106115.htmlTechArticlephp mailer class calls the remote SMTP server to send mail implementation method, mailersmtp This article describes the example of the php mailer class calling the remote SMTP server How to implement sending emails. Share it with everyone...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template