Get in touch
or send us a question?
CONTACT

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

?>