Swift 邮件程序连接被 symfony1.2 拒绝

发布于 2024-10-18 02:12:33 字数 1741 浏览 3 评论 0原文

我在发送邮件时遇到一些问题。我有一个运行 postfix 作为邮件服务器的 ubuntu 服务器。该 Web 应用程序基于 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 和错误字符串'连接被拒绝',

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

//adresses are examples
$to = "[email protected]";
$sender_email = "[email protected]";
// 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);

有人对此有任何想法吗?

谢谢!

Im having some problems sending mail. I have a ubuntu server running postfix as mailserver. The webapp is based on symfony 1.2 and has Swift 3 for mailing. Everyrhing is running on the same server. This is the code im trying to run:

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);
  }

}

This is the error message im getting:

There was an error while trying to send the email - locally:The SMTP connection failed to start [localhost:25]: fsockopen returned Error Number 111 and Error String 'Connection refused' ,

It's kind of strange, because i did manage to send a mail without swift with this code:

//adresses are examples
$to = "[email protected]";
$sender_email = "[email protected]";
// 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);

Anybody got any ideas about this??

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧街凉风 2024-10-25 02:12:34

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

It's not a problem with Symfony or PHP - your local SMTP server is unreachable. You likely have a configuration problem with your mail server that is preventing the SMTP server being available on it's native port (25).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文