PHP PEAR Send email sample

1. Installation

pear install -a Mail

2. Code sample

<?php
require_once "Mail.php";


$host = "smtp.awsvietnam.cloud";
$port = 587;
$username = "you@your-email-here.com";
$password = "YourPasswordHere";


$from = "website <you@your-email-here.com>";
$to = "Me <to@to-email-here.com>";


$subject = "Hi!";
$body = "Hi,\n\n Test from my website";


$headers = array ('From' => $from,
	'To' => $to,
	'Subject' => $subject);
	$smtp = Mail::factory('smtp',
	array ('host' => $host,
	'port' => $port,
	'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>");
}

?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: