Categories
Web API

Simple PHP Send an email

yum install php7-pear.noarch

Pear Install Mail – David Raleche

– pear7 install mail

– pear7 install net_smtp


<?php
$email_from = "[email protected]";
$email_subject = 'test subject ';
$email_message= 'test message ';


// Pear Mail Library
require_once "Mail.php";

$from = '<[email protected]>';
$to = '<[email protected]>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => '465',
    'auth' => true,
    'username' => '[email protected]',
    'password' => 'test!'
));

echo "DAVID<br>";
echo $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