doubang4881 2012-03-21 22:54
浏览 133
已采纳

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

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条回答 默认 最新

  • douyin4875 2012-03-21 23:25
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。