Following example help you to send email using Gmail SMTP with PHP,
You can download PHP mailer function from here GitHub.
require 'PHPMailerAutoload.php';
$from = '<yourname@gmail.com>';
$to = '<sendto@yahoo.com>';
$subject = 'Hello!';
$body = "Hello,\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' => '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>');
}
Enjoy!
No comments:
Post a Comment