无法使用gmail smtp和swift邮件程序发送邮件

我无法通过swift mailer上的gmail smtp发送电子邮件,这里是代码:</ p>

<前> &lt;?php

require_once'inc / swift_mailer / lib / swift_required.php';
$ transport = Swift_SmtpTransport :: newInstance('smtp.gmail.com',465,'ssl ')

  • &gt; setUsername('mysen2@gmail.com')
  • &gt; setPassword('bestpasswordever')
    ;
    $ transport-&gt; setLocalDomain('[127.0.0.1]'); \ n $ mailer = Swift_Mailer :: newInstance($ transport);

    $ message = Swift_Message :: newInstance($ transport)

  • &gt; setSubject('Test Mail')

  • &gt; setFrom(array(' mysen2@gmail.com'=&gt;'John Doe'))

  • &gt; setTo(array('testin3@gmail.com'))

  • &gt; setBody('这是测试消息。')\ n - &gt; addPart('&lt; q&gt;这是消息本身&lt; / q&gt;','text / html');

    if(!$ mailer-&gt; send($ message,$ failures))

    {
    die(“发生错误:&lt; br /&gt;”。$失败);
    }

?&gt;
</ code> </ pre>

错误消息:</ p>


致命错误: 带有
消息的未捕获异常'Swift_TransportException''无法与主机smtp一起建立连接
[无法找到套接字传输“ssl” - 您是否忘记在配置PHP时启用它? #-27264]'在
/swift_mailer/lib/classes/Swift/Transport/StreamBuffer.php:266
堆栈跟踪:#0
/swift_mailer/lib/classes/Swift/Transport/StreamBuffer.php(66) :
Swift_Transport_StreamBuffer-&gt; _establishSocketConnection()#1
/swift_mailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(117):
Swift_Transport_StreamBuffer-&gt; initialize(Array)#2
/ swift_mailer / lib /classes/Swift/Mailer.php(79):
Swift_Transport_AbstractSmtpTransport-&gt; start()#3
/usr/local/www/data/mail.php(19):
Swift_Mailer-&gt; send(Object (Swift_Message),数组)在第266行的
/swift_mailer/lib/classes/Swift/Transport/StreamBuffer.php
中抛出#4 {main} </ p>
</ blockquote>

我猜我的服务器没有包含open ssl库的问题:</ p>


[无法找到套接字传输“ssl” - 你忘了启用
它配置PHP时?</ p>
</ blockquote>

我该如何修复呢?</ p>

还</ h1>
\ n

使用gmails SMTP是否适用于s 每天结束50-100邮件? 或者我应该使用别的东西(你可以自由地建议并给我一些提示)?</ p>
</ div>

展开原文

原文

I cant send the email message via gmail smtp on swift mailer, here is the code:

<?php

require_once 'inc/swift_mailer/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
  ->setUsername('mysen2@gmail.com')
  ->setPassword('bestpasswordever')
  ;
$transport->setLocalDomain('[127.0.0.1]');
$mailer = Swift_Mailer::newInstance($transport);

$message = Swift_Message::newInstance($transport)
  ->setSubject('Test Mail')
  ->setFrom(array('mysen2@gmail.com' => 'John Doe'))
  ->setTo(array('testin3@gmail.com'))
  ->setBody('This is the test message.')
  ->addPart('<q>Here is the message itself</q>', 'text/html');

    if (!$mailer->send($message, $failures))
    {
        die("Errors occurred:<br/>" . $failures);
    }

?>

And the error message:

Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? #-27264]' in /swift_mailer/lib/classes/Swift/Transport/StreamBuffer.php:266 Stack trace: #0 /swift_mailer/lib/classes/Swift/Transport/StreamBuffer.php(66): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /swift_mailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(117): Swift_Transport_StreamBuffer->initialize(Array) #2 /swift_mailer/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() #3 /usr/local/www/data/mail.php(19): Swift_Mailer->send(Object(Swift_Message), Array) #4 {main} thrown in /swift_mailer/lib/classes/Swift/Transport/StreamBuffer.php on line 266

I guess its a problem with my server not containing the open ssl library:

[Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?

How can I fix that , then?

also

Is using gmails SMTP good for sending like 50-100 mails per day? Or I should use something else (you're free to suggest and give me some tips)?

1个回答



您可以修复 [无法找到套接字传输“ssl” - 您是否忘记在配置PHP时启用它 ?</ code>通过使用 - with-ssl [= DIR] </ code>选项重新编译PHP。</ p>

为了能够做到这一点,你有 将OpenSSL库安装到您的服务器上。 根据您的操作系统,您可以在Debian / Ubuntu上执行 apt-get install openssl-dev </ code>,或者在RedHat / CentOS / Fedora上执行 yum install openssl-devel </ code>。< / p>

或者,您可以下载并编译最新版本的 OpenSSL </ a >你自己并使用PHP。</ p>

如果你没有运行你的服务器,那么你需要让你的主机为你启用PHP的SSL。</ p>

另外</ strong>:Gmail可以正常运行,每天发送50-100封电子邮件。 但这取决于。 查看他们的 Gmail计划政策 细节。 听起来如果您与每天发送电子邮件的50-100人之间存在预先存在的关系,那么您可能不会违反任何条款,但您​​可能希望通过直接联系他们或更多地搜索他们的条款来确认 。</ p>
</ div>

展开原文

原文

You can fix the [Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? by recompiling PHP using the --with-ssl[=DIR] option.

In order to be able to do that, you have to install the OpenSSL libraries onto your server. Depending on your OS, you can do something like apt-get install openssl-dev on Debian/Ubuntu, or yum install openssl-devel on RedHat/CentOS/Fedora.

Alternatively, you can just download and compile the latest version of OpenSSL yourself and use that with PHP.

If you do not run your server, then you need to ask your host to enable SSL in PHP for you.

Also: Gmail may work okay for sending 50-100 emails per day. It depends though. See their Program Policies for Gmail which does not go into a lot of detail. It sounds like if you have a pre-existing relationship with the 50-100 people you are emailing per day, then you may not be violating any terms, but you may want to confirm that by contacting them directly or doing more searching about their terms.

doubi1818
doubi1818 非常感谢 :)!
8 年多之前 回复
drxd54816
drxd54816 我近年来对FreeBSD的经验不多。 看起来openssl-1.0.0_10可能是你想要的端口。 然后,您必须找到具有SSL支持的PHP端口(如果存在)。
8 年多之前 回复
dt246813579
dt246813579 我正在使用freebsd所以我在这里有端口:/
8 年多之前 回复
立即提问
相关内容推荐