【问题标题】:Laravel 5.4 - Connection timeout when Sending email with attachment using SMTP GmailLaravel 5.4 - 使用 SMTP Gmail 发送带附件的电子邮件时连接超时
【发布时间】:2018-01-15 11:53:35
【问题描述】:

当我尝试发送不带附件的电子邮件时,它也可以正常工作。但是当我附加一个文件时,它不起作用并给我这个错误消息:

Swift_TransportException 连接到 tcp://smtp.gmail.com:587 定时 出去

这是我的代码:

...
public function build(){
  return $this
    ->subject('Welcome')
    ->markdown('emails.welcome')
    ->attach(storage_path('public/files/file.pdf'), [
        'as' => 'file.pdf',
        'mime' => 'application/pdf'
    ]);
}
...

请帮忙!

【问题讨论】:

  • 感谢您的回复。但我不认为这是导致问题的原因。我的问题仅在我尝试发送带有附件的电子邮件时出现。
  • 我也在尝试使用 mailtrap.io 发送它,但问题仍然存在

标签: email laravel-5


【解决方案1】:

使用realpath() 而不是storage_path()

所以代码应该是这样的:

...
public function build(){
  return $this
    ->subject('Welcome')
    ->markdown('emails.welcome')
    ->attach(realpath('storage/files/file.pdf'), [
        'as' => 'file.pdf',
        'mime' => 'application/pdf'
    ]);
}
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-17
    • 2013-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 2021-03-26
    相关资源
    最近更新 更多