Reputation: 1827
I am trying to use PEAR Mail to send from my gmail address using below code,
<?php
include("Mail.php");
echo "This test mail for authentication";
try{
$from_name = "Test";
$to_name = "from name";
$subject = "hai";
$mailmsg = "Happy morning";
$From = "From: ".$from_name." <[email protected]>";
$To = "To: ".$to_name." <[email protected]>";
$recipients = "[email protected]";
$headers["From"] = $From;
$headers["To"] = $To;
$headers["Subject"] = $subject;
$headers["Reply-To"] = "[email protected]";
$headers["Content-Type"] = "text/plain";
$smtpinfo["host"] = "smtp.gmail.com";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "[email protected]";
$smtpinfo["password"] = "mypassword";
//$smtpinfo["debug"]=True;
$mail_object =& Mail::factory("smtp", $smtpinfo);
$mail_object->send($recipients, $headers, $mailmsg);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
}catch(Exception $e){
echo 'Caught exception: ', $e->getMessage(), "\n";
}
echo "<br>Fin";
?>
this code not return any error or warning , it simply shows "Message successfully sent!" but, mail not receiver to mail the address.
can any one please tell what problem in mycode or what actually happening.,
Upvotes: 0
Views: 1242
Reputation: 39570
The first thing I see is that you have a mistake: Your check checks against an variable called $mail
, but everything else refers to $mail_object
. If that's in your actual code, then I'm guessing that might be part of it.
Some basic checks:
smtp.gmail.com
or using telnet to open a connection to port 25: telnet smtp.gmail.com 25
Beyond that, it looks like GMail requires TLS or SSL, which means you have to use port 587
or port 465
. I don't know if that package can handle encrypted connections, though. (Even on port 25
, GMail requires SSL encryption.) That may preclude this from working at all.
Upvotes: 1