PHP send mail with SMTP Authentication

<?php

require_once "Mail.php";

 

$from = "XXXXXX@yourDOMAIN.com";

$to = "XXXXXXX@gmail.com";

$subject = "Hi!";

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

 

$host = "Localhost";

$username = "XXXXXXXX@yourDOMAIN.com";

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

 }

?>

  • 9 Users Found This Useful
Was this answer helpful?

Related Articles

Sending email using CDOSYS

If you are using a Windows 2000 / 2003 Server, or even XP Pro chances are that CDOSYS is your...

Upload file through ASP.net

<% @Page Language="C#" %><html><head>  <title>File upload...

Mailenable Component - Mail Code

Mailenable Component - Mail Code <%@ Language=VBScript %> <% Dim oMail Set oMail =...

How to create MSAccess Database DSN in Plesk Control Panel?

To Create DSN for MSAccess Database do following steps. 1. Access your control panel 2. Click on...

Create MS Access DSNLess connection string

Many people have requested this so here it is: "DRIVER={Microsoft Access Driver (*.mdb)};...