dongqiao3927 2011-08-15 05:10
浏览 26
已采纳

邮件不是在php pear邮件包中发送的

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." <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(), "
";
}
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.,

  • 写回答

1条回答 默认 最新

  • doucheng9634 2011-08-15 07:32
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog