简体   繁体   English

无法使用php-pear 5.6发送电子邮件

[英]cant send email with php-pear 5.6

I have a php scrip that emails. 我有一封电子邮件的PHP脚本。 After the recent update to php and php-pear to 5.6 it no longer works and I get a authentication error. 在对php和php-pear的最新更新到5.6之后,它不再起作用,并且出现身份验证错误。

$from = "no-reply@mydomain.net";
 $port = "587";
 $to=$d_uname;
 $host = "smtp.sendgrid.net";
 $username = "username";
 $password = "password";

         $headers = array ('From' => $d_replyto,
           'To' => $to,
           'Subject' => $d_subject,
       'MIME-Version' => "1.0",
       'Content-type' => "text/plain; charset=utf-8",
     );
         $smtp = Mail::factory('smtp',
           array ('host' => $host,
             'port' => $port,
             'auth' => true,
             'username' => $username,
             'password' => $password));

 #Email it
 if (PEAR::isError($smtp)) {
     error_log("<p>" . $smtp->getMessage() . "</p>");
    }
 $mail = $smtp->send($to, $headers, $d_message);

When trying to send emails this way I get the following error: 当尝试通过这种方式发送电子邮件时,出现以下错误:

authentication failure [SMTP: STARTTLS failed (code: 220, response: Begin TLS negotiation now)]

Any ideas what's wrong here? 有什么主意吗? Downgrading PHP and PHP-pear resolves the issue. 降级PHP和PHP-pear可以解决此问题。

Cheers! 干杯!

I had the same problem and was looking for an answer. 我有同样的问题,正在寻找答案。 This question is kinda old but I will leave a few words of explanation for someone else. 这个问题有点老了,但我会给别人一些解释。 The problem is that PEAR SMTP class, which extend PEAR Mail, is not yet updated for php 5.6. 问题在于,扩展PEAR Mail的PEAR SMTP类尚未针对php 5.6更新。 Since php 5.6 you won't be able to use PEAR Mail for "unclean" TLS connections. 从php 5.6开始,您将无法使用PEAR Mail进行“不干净的” TLS连接。 It has something to do with OpenSSL changes. 它与OpenSSL更改有关。 It will work for some SMTP's, like Gmail's on port 465, but nowhere else. 它适用于某些SMTP,例如端口465上的Gmail,但没有其他地方。 You need to use 'auth' => false or switch to PHP Mailer 您需要使用'auth'=> false或切换到PHP Mailer

You can hard-code the options required to allow self-signed certificates by including them on line 208 of Socket.php 您可以通过在Socket.php的第208行中包含自签名证书来对这些选项进行硬编码

else{         // if $fp does exist
  stream_context_set_option($fp, 'ssl', 'verify_peer', false);
  stream_context_set_option($fp, 'ssl', 'allow_self_signed', true);
  stream_context_set_option($fp, 'ssl', 'verify_peer_name', false);
    }

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

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