【问题标题】:SwiftMailer using G Suite IssueSwiftMailer 使用 G Suite 问题
【发布时间】:2017-05-29 12:01:54
【问题描述】:

我正在尝试在我的服务器上设置 SwiftMailer。我正在使用 SwiftMailer 文档中的示例配置进行测试。我有一个付费的 G Suite 帐户,但尚未在服务器上完成 SSL 设置。我正在运行 Cent OS 6.8 和 Apache 2.2。我用谷歌搜索了所有我能想到的东西,并尝试了所有提出的解决方案,但都没有成功。

我的脚本如下,显然我的电子邮件地址和凭据在真实脚本中是正确的。我很感激任何建议。

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

require_once('swiftmailer-5.x/lib/swift_required.php');

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp-relay.gmail.com', 25)
     ->setUsername('myemail@mydomain.com')
     ->setPassword('*****')
;

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('Swift Mailer Test')
  ->setFrom(array('my from address'))
  ->setBody('Here is the message itself')
  ;

// Send the message
$failedRecipients = array();
$numSent = 0;
$to = array('another@email.com' => 'Joe');

foreach ($to as $address => $name)
{
  if (is_int($address)) {
    $message->setTo($name);
  } else {
    $message->setTo(array($address => $name));
  }

  $numSent += $mailer->send($message, $failedRecipients);
}

printf("Sent %d messages\n", $numSent);


?>

当我运行这个脚本时,我得到以下非常模糊的错误:

“致命错误:在 /var/www/html/appreciate-erp/swiftmailer 中出现未捕获的异常 'Swift_TransportException' 和消息“无法与主机 smtp-relay.gmail.com [连接超时 #110] 建立连接” -5.x/lib/classes/Swift/Transport/StreamBuffer.php:269 堆栈跟踪:#0 /var/www/html/appreciate-erp/swiftmailer-5.x/lib/classes/Swift/Transport/StreamBuffer。 php(62): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /var/www/html/appreciate-erp/swiftmailer-5.x/lib/classes/Swift/Transport/AbstractSmtpTransport.php(113): Swift_Transport_StreamBuffer->initialize(数组) #2 /var/www/html/appreciate-erp/swiftmailer-5.x/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() #3 /var/www/html/appreciate -erp/mailtest.php(42): Swift_Mailer->send(Object(Swift_Message), Array) #4 {main} 抛出 /var/www/html/appreciate-erp/swiftmailer-5.x/lib/classes/ Swift/Transport/StreamBuffer.php 在线 269"

【问题讨论】:

  • 哇,堆栈溢出。是我说的吗?

标签: swiftmailer


【解决方案1】:

截至https://support.google.com/a/answer/176600,G-Suite 上的 SMTP 中继似乎应用了 IP 地址限制。 “无法连接”错误可能是由于缺少配置或尝试从配置的另一个 IP 地址连接的结果。希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2019-07-27
    • 2018-10-20
    • 1970-01-01
    • 2021-03-17
    • 1970-01-01
    • 2020-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多