Use the PHP Mailer class to call the remote SMTP server to send the email cocould not execute:/var/Qmail/bin/sendmai

Source: Internet
Author: User
Tags php email word wrap qmail

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://download.csdn.net/source/2549515

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:

<? PHP

Require '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.
$ 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"; // user name on the remote SMTP Server
$ Mail-> Password = "yourpassword"; // the password of the user on your remote SMTP Server

// $ Mail-> issendmail (); // tell this class to use the Sendmail component. If no Sendmail component is set up, comment out this component; otherwise

"Cocould not execute:/var/Qmail/bin/sendmail"Error prompt

$ Mail-> addreplyto ("yourname@yourdomain.com", "first last ");

$ Mail-> from = "fromname@yourdomain.com ";
$ Mail-> fromname = "first last ";

$ To = "toname@domain.com ";

$ Mail-> addaddress ($ );

$ 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 ();
}
?>

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!

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.