PHP Mailer class invoke remote SMTP server send mail implementation method _php tips

Source: Internet
Author: User
Tags php email word wrap server port

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.

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.