开发者

Mail not sent in php pear mail package

开发者 https://www.devze.com 2023-03-28 15:58 出处:网络
I am trying to use PEAR Mail to send from my gmail address using below code,开发者_JAVA技巧 <?php

I am trying to use PEAR Mail to send from my gmail address using below code,开发者_JAVA技巧

<?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." <frommail@gmail.com>"; 
$To = "To: ".$to_name." <tomail@gmail.com>"; 

$recipients = "tomail@gmail.com"; 
$headers["From"] = $From; 
$headers["To"] = $To; 
$headers["Subject"] = $subject; 
$headers["Reply-To"] = "gunarsekar@gmail.com"; 
$headers["Content-Type"] = "text/plain"; 

$smtpinfo["host"] = "smtp.gmail.com"; 
$smtpinfo["port"] = "25"; 
$smtpinfo["auth"] = true; 
$smtpinfo["username"] = "mymail@gmail.com"; 
$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.,


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:

  • Did you check to make sure that you have POP or IMAP enabled in Gmail?
  • Have you set up this account with the same username and password on a normal machine, to ensure you can send and receive email outside of PHP?
  • Verify that you can even talk to the GMail server (that it isn't blocked for some reason) by pinging smtp.gmail.com or using telnet to open a connection to port 25: telnet smtp.gmail.com 25
  • Read over the Gmail help for sending email.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消