简体   繁体   English

邮件未发送 php 梨邮 package

[英]Mail not sent in php pear mail package

I am trying to use PEAR Mail to send from my gmail address using below code,我正在尝试使用 PEAR Mail 使用以下代码从我的 gmail 地址发送,

<?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 .我看到的第一件事是您有一个错误:您的检查检查了一个名为$mail的变量,但其他所有内容都引用了$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?您是否检查以确保在 Gmail 中启用了 POP 或 IMAP?
  • 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?您是否在普通机器上使用相同的用户名和密码设置此帐户,以确保您可以在 PHP 之外发送和接收 email?
  • 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 Verify that you can even talk to the GMail server (that it isn't blocked for some reason) by 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.阅读 Gmail 帮助以发送 email。

Beyond that, it looks like GMail requires TLS or SSL , which means you have to use port 587 or port 465 .除此之外,看起来 GMail 需要 TLS 或 SSL ,这意味着您必须使用端口587或端口465 I don't know if that package can handle encrypted connections, though.不过,我不知道 package 是否可以处理加密连接。 (Even on port 25 , GMail requires SSL encryption.) That may preclude this from working at all. (即使在端口25上,GMail 也需要 SSL 加密。)这可能完全无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM