2

我已经完成了编写 PHP 代码以便使用 POP3 发送电子邮件。但是每次我遇到错误时

[错误] => 连接到 POP3 服务器引发 PHP 警告:[errno] => 2 [errstr] => fsockopen() [function.fsockopen]: 无法连接到 pop3.yahoo.com:465(连接尝试failed ) SMTP -> ERROR: Failed to connect to server: 连接尝试失败,因为连接方在一段时间后没有正确响应,

这是我的代码。

<?php
require_once('/class.phpmailer.php');
require_once('/class.pop3.php'); // required for POP before SMTP

$pop = new POP3();
$pop->Authorise('pop3.yahoo.com',465,10, 'arsalansherwani@yahoo.com',     
'******',1);

$mail = new PHPMailer();
$msg='Name';
//$body             = file_get_contents('contents.html');
//$body             = eregi_replace("[\]",'',$body);
$address='arsalanjawed619.com';
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->Host     = 'pop3.yahoo.com';

$mail->SetFrom('arsalansherwani@yahoo.com', 'arsalan');

$mail->AddReplyTo("arsalansherwani@yahoo.com","arsalan");

$mail->Subject    = "PHPMailer Test Subject via POP before SMTP, basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";       

$mail->MsgHTML($msg);

$address = "arsalanjawed619@yahoo.com";
$mail->AddAddress($address, "arsalan");

//$mail->AddAttachment("images/phpmailer.gif");      // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment


if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>

任何帮助将不胜感激

4

4 回答 4

4

You don't send emails with pop3, this is to retrieve them. You send emails with SMTP for example...

于 2013-05-02T11:00:43.467 回答
1

you are connecting to wrong server. connect to smtp server. i think below code will work.

 $pop->Authorise('smtp.mail.yahoo.com',465,10, 'arsalansherwani@yahoo.com',     
 '******',1);
于 2013-05-02T13:49:48.590 回答
1

您需要为 POP3 和 SMTP 使用不同的服务器。

POP3 用于接收电子邮件

SMTP 用于发送电子邮件

你需要使用

$mail->Host= 'smtp.mail.yahoo.com';

代替

$mail->Host = pop3.yahoo.com';

$pop->Authorise('pop3.yahoo.com',465,10, 'arsalansherwani@yahoo.com',
'******',1);

$pop->Authorise('pop.mail.yahoo.com',465,10,'arsalansherwani@yahoo.com',
'******',1);

分别使其工作

<?php
require_once('class.phpmailer.php');/*Including classes from php mailer*/
require_once('class.pop3.php'); 
require_once('class.smtp.php');
$pop = new POP3(); /*Create a new object for pop3*/
$pop->Authorise('mailserver001.mydomain.com', 110, 30, 'username', 'password', 1); /*login in to pop3 */
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Debugoutput = 'html';
$mail->SMTPDebug = 2;
$mail->SMTPOptions = array(
                'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true)
               ); /*Skip SSL Errors(if any),generally not needed*/
$mail->Host     = 'mailserver001.mydomain.com'; /*SMTP host*/
$mail->SetFrom('info@mydomain.com', 'Name');/*Email content */
$mail->AddReplyTo("info@mydomain.com","Name");
$mail->Subject    = "Welcome";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; 
$mail->MsgHTML('HTML');
$address = "myname@otherdomain.com";
$mail->AddAddress($address, "Name");
if(!$mail->Send()) {/*Send Email*/
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}  
?>

要为免费的 Yahoo Mail 帐户启用 POP3:

转到 Gear 并单击设置:

单击帐户导航,然后单击编辑按钮:

单击 POP 的单选按钮,选择是否包含垃圾邮件,然后单击保存:

打开 POP3 后,Yahoo Mail 的设置为:

接收邮件服务器设置:

免费雅虎帐户:pop.mail.yahoo.com(端口 995,需要 SSL)

Yahoo Plus 帐户:plus.pop.mail.yahoo.com(端口 995,需要 SSL)

使用您的完整电子邮件地址和密码进行登录。

免费的 Yahoo Mail 帐户应使用发送服务器设置:smtp.mail.yahoo.com,端口 587(需要 SSL/TLS)

于 2016-11-19T11:24:31.167 回答
0

pop3 是从邮件服务器检索电子邮件所需的邮局协议。您需要使用 smtp 协议。连接到具有适当授权的 smtp 服务器。一些 smtp 服务器可能需要 ssl

于 2013-05-02T11:15:56.613 回答