How to send an email with php ?
yum install php7-pear.noarch
Pear Install Mail – David Raleche
– pear7 install mail
– pear7 install net_smtp
<?php
$email_from = "test@gmail.com";
$email_subject = 'test subject ';
$email_message= 'test message ';
// Pear Mail Library
require_once "Mail.php";
$from = '<test@test.com>';
$to = '<test@gmail.com>';
$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' => 'test@test.com',
'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>');
}
?>
Comments