php Zend 邮件 Gmail SMTP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1094137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:55:51  来源:igfitidea点击:

Zend Mail Gmail SMTP

phpzend-frameworksslemailgmail

提问by bucabay

Hi I'm trying to send some emails via gmail from the Zend_Mail module. This is my code:

嗨,我正在尝试从 Zend_Mail 模块通过 gmail 发送一些电子邮件。这是我的代码:

$config = array(
    'ssl' => 'tls',
    'port' => 587,
    'auth' => 'login',
    'username' => '[email protected]',
    'password' => 'password'
);
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);

Error:

错误:

Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in /library/Zend/Mail/Protocol/Smtp.php on line 206 Unable to connect via TLS

警告:stream_socket_enable_crypto() [streams.crypto]:此流不支持第 206 行 /library/Zend/Mail/Protocol/Smtp.php 中的 SSL/crypto Unable to connect via TLS

I tried telling my hosting provider to enable the openssl.dll in phi.ini

我试着告诉我的托管服务提供商在 phi.ini 中启用 openssl.dll

But they say that isn't necessary since the server is in Linux and it doesn't need to enable the openssl.dll to work with TLS or SSL.

但是他们说这不是必需的,因为服务器在 Linux 中并且不需要启用 openssl.dll 来使用 TLS 或 SSL。

Is my hosting provider wrong or I'm I doing something wrong in my code.

是我的托管服务提供商错了,还是我的代码做错了。

Thanks in advance

提前致谢

Fabian

法比安

回答by bucabay

openssl.dll is the windows openssl extension.

openssl.dll 是 windows openssl 扩展。

On Linux you need to compile PHP with OpenSSL support. http://www.php.net/manual/en/openssl.installation.php

在 Linux 上,您需要使用 OpenSSL 支持编译 PHP。 http://www.php.net/manual/en/openssl.installation.php

You need OpenSSL for PHP sockets and stream functions to use TLS. Zend uses these functions and thus require the same.

您需要针对 PHP 套接字和流函数的 OpenSSL 才能使用 TLS。Zend 使用这些功能,因此需要相同的功能。

回答by RondyS

I was having a similar problem here is what worked; Using Zend mail transport and yahoo smtp:

我在这里遇到了类似的问题,这是有效的;使用 Zend 邮件传输和 yahoo smtp:

$mailhost= 'smtp.example.com';
$mailconfig = array(
    'auth'     => 'login',
    'username' => '[email protected]',
    'password' => 'topsecret',
    'port'     => '465',
    'ssl'      => 'ssl'
);
$transport = new Zend_Mail_Smtp($mailhost, $mailconfig);
Zend_Mail::setDefaultTransport($transport);

This produced an error: "Permission denied" and no mail was sent. After three weeks of trying all solutions I could find the one that worked was changing: $transport to; $transport = new Zend_Mail_Transport_Sendmail('[email protected]',$mailhost, $mailconfig);

这产生了一个错误:“权限被拒绝”并且没有发送邮件。在尝试了所有解决方案三周后,我发现有效的解决方案正在改变:$transport to; $transport = new Zend_Mail_Transport_Sendmail('[email protected]',$mailhost, $mailconfig);

works as expected...

按预期工作...

回答by Snowcore

It's very comfortably to use Zend_Mail::setDefaultTransportmethod

使用Zend_Mail::setDefaultTransport方法很舒服

回答by Basher

Try setting ssl:// as prefix for the hostname and use 465 as port.

尝试将 ssl:// 设置为主机名的前缀并使用 465 作为端口。