"send email using the gmail smtp server from a php page" Code Answer

2
// pear mail library
require_once "mail.php";

$from = '<fromaddress@gmail.com>';
$to = '<toaddress@yahoo.com>';
$subject = 'hi!';
$body = "hi,nnhow 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' => 'johndoe@gmail.com',
        'password' => 'passwordxxx'
    ));

$mail = $smtp->send($to, $headers, $body);

if (pear::iserror($mail)) {
    echo('<p>' . $mail->getmessage() . '</p>');
} else {
    echo('<p>message successfully sent!</p>');
}
By hjalpmig on June 22 2022

Answers related to “send email using the gmail smtp server from a php page”

Only authorized users can answer the Search term. Please sign in first, or register a free account.