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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程