Send Email From PHP Using SMTP Authentication

Login to your root SSH and copy/use following command line to your SSH line.

PHP- Code:

pear install Mail;pear install Net_SMTP;pear install Auth_SASL;

After above command, you can now use the following php script and send real emails.
====================================================
PHP- Code:

<?php
require_once “Mail.php”;
$from = “MyName <name@myemail.com>”;
$to = “TargetName <name@targetemail.com>”;
$subject = “Hi!”;
$body = “Hi,\n\nHow are you?”;
$host = “mail.mailserver.com”;
$username = “name@myemail.com”;
$password = “my_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>”);
}
?>
=====================================================================================
Mail.php is server side pear, but you may download this and see the full class:
http://download.pear.php.net/package/Mail-1.1.13.tgz    More information: http://pear.php.net/package/Mail
=====================================================================================

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s