Tuesday, 1 October 2013

PHP Script to Send Email Using SMTP Authentication

<?php
 require_once "Mail.php";
 
 $from = "Susan Sender <sender@example.com>";
 $to = "Rachel Recipient <recipient@example.com>";
 $subject = "Hi!";
 $body = "Hi,\n\nHow are you?";
 
 $host = "smtpcorp.com"; 
// Enter your SMTP2GO account's SMTP server.
$port = "2525";
// 8025, 587 and 25 can also be used.
$username = "smtp_username"; $password = "smtp_password"; $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>");  } ?>

No comments:

Post a Comment