Knowledge Essentials - 3Essentials Hosting

Sending mail with PHP using SMTP-auth

Article ID: 394

 Back to Search

To protect 3Essentials network, servers, and customers from spamming, 3Essentials requires the use of SMTP-auth for all methods of sending email.  The basic PHP Mail function does not support SMTP-auth, therefore cannot be used. 

To find out more about SMTP-auth and enabling smtp-auth on PHP based open sourced solutions (like phpBB, OScommerce, etc), see this article: What is SMTP-AUTH?

To write your own PHP code to send email using SMTP-auth, we've made the PHP PEAR Mail package available for usage (which does support smtp-auth).  The following PHP code sample shows how to use this feature in your PHP code to send an email:

require_once "Mail.php";

$from = "Your Name <>";
$to = "John Smith <>";
$subject = "This is my subject";
$body = "Hi,\n\nHow are you?";

$host = "localhost";
$username = "";
$password = "yourpassword";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!!</p>");


NOTE: With PHP5.4 it may be necessary to prepend your call to Mail.php with an ampersand '@'. For example:

@require_once "Mail.php";


Be sure to change the applicable values (from, to, subject, body, username, password) to your own. This code will work with either PHP 4 or PHP 5.

  • Please do not name the file as Mail.php as we're giving reference to the Mail.php in the code which is located in the server.  Since this is essential for the code to work, you can name the file as mailer.php or mailsend.php for this code.

  • If  you happen to get the following error, then add a line in the php.ini file found under your HTTPDOCS:
    • Warning: main(Mail.php) [function.main]: failed to open stream: No such file or directory in E:\inetpub\vhosts\domainname\httpdocs\filename.php on line 2

      Fatal error: main() [function.require]: Failed opening required 'Mail.php' (include_path='.;./includes;./pear') in E:\inetpub\vhosts\\httpdocs\filename.php on line 2


The line to be added in php.ini is:

  • For WEB10: include_path=".;E:\Program Files\SWsoft\Plesk\Additional\Php\PEAR\;./includes;./pear"
  • For WEB12: include_path=".;E:\Program Files\SWsoft\Plesk\Additional\Php\PEAR\;./includes;./pear"
  • For WEB14: include_path=".;E:\Program Files\SWsoft\Plesk\Additional\Php\PEAR\;./includes;./pear"
  • For WEB16: include_path=".;E:\Program Files\SWsoft\Plesk\Additional\Php\PEAR\;./includes;./pear"
  • For WEB18: include_path=".;E:\Program Files\SWsoft\Plesk\Additional\Php\PEAR\;./includes;./pear"
  • For WEB20: include_path=".;F:\Program Files\SWsoft\Plesk\Additional\Php\pear;./includes;./pear"
  • For WEB22: include_path=".;E:\Program Files\Parallels\Plesk\Additional\Php\pear;./includes;./pear"
  • For WEB24: include_path=".;E:\Program Files\Parallels\Plesk\Additional\Php\pear;./includes;./pear"
  • For WEB26: include_path=".;E:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP5\Pear;./includes;./pear"
  • For WEB28: include_path=".;E:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP5\Pear;./includes;./pear
  • For cPanel based systems (WEB9, WEB11,WEB13): include_path = ".:/usr/lib/php:/usr/local/lib/php:/usr/local/cpanel/3rdparty/lib/php"



Downloads Associated With This Article
No downloads are currently associated with this article.