dimanche 20 mai 2018

Laravel: attach remote file to an email

I have a system which allow users to upload their attachments locally to send it later on. and, I have another server that send the emails according the jobs in database (2 different servers) Now, I have a problem attaching the files from server #1 in server #2, here is what I tried:

  1. I tried to attach the files with a URL, means, instead of sending the full path /home/site/public/attachment/test.jpg (which is impossible because this is another server with a different root) I changed it to a URL (https://example.com/attachment/test.jpg), it doesn't work, and returns an error:

Swift_IoException: Unable to open file for reading

  1. I tried to do it with fileGetContent, like the following:

    //because its ssl Im adding this:
    $arrContextOptions=array(
    "ssl"=>array(
    "verify_peer"=>false,
    "verify_peer_name"=>false));
    
    $toAttach = file_get_contents($path.$item->name, false, stream_context_create($arrContextOptions));
    //Before I had: $toAttach = $path.$item->name;
    
    $markdown->attachData($toAttach, [
    'as' => $item->name,
    'mime' => $item->type
    ]);
    
    

But here, it give me back a different error:

ErrorException: preg_match() expects parameter 2 to be string, array given in /...../vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/ParameterizedHeader.php:189

Can you help me? anyone tried to attach files remotely? maybe share the folder from the server somehow?

Thank you!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2KEWF56
via IFTTT

Aucun commentaire:

Enregistrer un commentaire