【问题标题】:Swift mailer connection refused with symfony1.2Swift 邮件程序连接被 symfony1.2 拒绝
【发布时间】:2011-02-19 10:12:48
【问题描述】:

我在发送邮件时遇到了一些问题。我有一个运行 postfix 作为邮件服务器的 ubuntu 服务器。该网络应用程序基于 symfony 1.2 并具有用于邮件的 Swift 3。 Everyrhing 在同一台服务器上运行。这是我试图运行的代码:

public static function sendMailLocal($mailFrom, $mailto, $subject, $mailBody, $prevError)
{
  $mailer = null;
 try
  {
    $connection  = new Swift_Connection_SMTP('localhost', '25');

    $mailer = new Swift($connection);
    // Create the mailer and message objects
  $message = new Swift_Message($subject, $mailBody, 'text/html');

    // Send
    $mailer->send($message, $mailto, $mailFrom);
    $mailer->disconnect();
  }
catch (Exception $e)
  {
    if($mailer != null)
      $mailer->disconnect();
    throw new EmailTransferException ("There was an error while trying to send the email - locally:" . $e->getMessage() . " , first error:" . $prevError);
  }

}

这是我得到的错误消息:

尝试在本地发送电子邮件时出错:SMTP 连接无法启动 [localhost:25]:fsockopen 返回错误号 111 和错误字符串“连接被拒绝”,

这有点奇怪,因为我确实设法使用以下代码在没有 swift 的情况下发送邮件:

//adresses are examples
$to = "john.doe@mail.com";
$sender_email = "someone@mail.com";
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: <'.$to.'>' . "\r\n";
$headers .= 'From: John Doe<'.$sender_email.'>' . "\r\n";
// Mail it
$success = mail($to, "test from server", "msg", $headers);

有人对此有任何想法吗?

谢谢!

【问题讨论】:

  • mail() 使用 sendmail,而不是 SMTP。听起来像是一个配置问题——你 1000% 确定有一个邮件服务器在运行吗?你能用其他方式到达吗?
  • 我可以这样做:/etc/init.d/postfix start * 启动 Postfix 邮件传输代理 postfix ...完成。
  • 如果你只做telnet localhost 25会发生什么?它是连接还是拒绝?
  • 从我的计算机我无法访问端口 25 上的服务器。从服务器我真的不知道该怎么做...它没有 telnet
  • 对不起...答案是:不,我连服务器都连接不上25端口!

标签: php email symfony1 swiftmailer


【解决方案1】:

这不是 Symfony 或 PHP 的问题 - 您的本地 SMTP 服务器无法访问。您的邮件服务器可能存在配置问题,导致 SMTP 服务器无法在其本机端口 (25) 上使用。

【讨论】:

  • 好吧,这家伙是对的。也许我会提出一个关于后缀的单独问题......
猜你喜欢
  • 1970-01-01
  • 2016-02-21
  • 1970-01-01
  • 1970-01-01
  • 2012-01-03
  • 2013-09-23
  • 1970-01-01
  • 2017-08-08
  • 2016-11-19
相关资源
最近更新 更多