PHP send mail with SMTP Authentication

<?php

require_once "Mail.php";

 

$from = "[email protected]";

$to = "[email protected]";

$subject = "Hi!";

$body = "Hi,\n\nHow are you?";

 

$host = "Localhost";

$username = "[email protected]";

$password = "XXXXXXXXX";

 

$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>");

 }

?>

  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

Create MS Access DSNLess connection string

Many people have requested this so here it is: "DRIVER={Microsoft Access Driver...

Do you support ASP?

 Yes, we support ASP.

Do you support Cold Fusion?

We do not support or Cold Fusion on our shared hosting servers, however you are more than welcome...

Do you support Servlets/JSP on Windows Server?

Yes, we support Servlet/JSP on our Windows Server.

Enable Parent Paths in Plesk - Windows Server

Many scripts use a function called parent paths. If you are running one of these scripts and...