[PHP] Ajouter une pièce jointe à la volée à un email Swift

Publié le 16/10/2018 • Mis à jour le 16/10/2018

English language detected! 🇬🇧

  We noticed that your browser is using English. Do you want to read this post in this language?

Read the english version 🇬🇧

Parce que j'oublie toujours ! 🤔


// Create attachment on the fly
$swiftAttachment = new \Swift_Attachment('ics data', 'mycalendar.ics', 'text/calendar');

$message = (new \Swift_Message())
    ->setSubject('Subject')
    ->setFrom('from@email.com')
    ->setTo('to@email.com')
    ->setCc('cc@email.com')
    ->setBcc('bcc@email.com')
    ->setReplyTo('replyto@email.com')
    ->setBody($body, 'text/html');

// Attach the file to the email message
$message->attach($swiftAttachment);

 Plus sur Stackoverflow