(1)first download pear package to send email following link is given:
https://pear.php.net/package/PEAR/download
& find Mail.php file
(2)find code for sending email with smtp setting details save this file name by email.php under same folder where Mail.php file is stored run it :
<?php
require_once "Mail.php";
$from = "youremailid@gmail.com";
$to = "omchandmaurya1@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "youremailid@gmail.com";
$password = "yourpassword";
$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>");
}
?>
https://pear.php.net/package/PEAR/download
& find Mail.php file
(2)find code for sending email with smtp setting details save this file name by email.php under same folder where Mail.php file is stored run it :
<?php
require_once "Mail.php";
$from = "youremailid@gmail.com";
$to = "omchandmaurya1@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "youremailid@gmail.com";
$password = "yourpassword";
$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>");
}
?>
No comments:
Post a Comment