2

When I am trying to sending an email without attachment, its working as well. But when I attach a file, its not working and give me this error message:

Swift_TransportException Connection to tcp://smtp.gmail.com:587 Timed Out

Here is my code:

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

Please help!

arhakim
  • 164
  • 2
  • 16
  • check this https://stackoverflow.com/questions/25572907/using-gmail-smtp-via-laravel-connection-could-not-be-established-with-host-smtp – Satya Aug 08 '17 at 04:40
  • Thanks for your reply. But I don't think that was causing the issue. My issue is occurred only when I try to sending email with an attachment. – arhakim Aug 08 '17 at 04:54
  • I am also trying to send it using mailtrap.io and the issue still happened – arhakim Aug 08 '17 at 04:56

1 Answers1

0

Use realpath() instead of storage_path()

So the code would be like this:

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