Skip to content

Instantly share code, notes, and snippets.

@vojtasvoboda
Created January 4, 2016 10:36
Show Gist options
  • Save vojtasvoboda/aac55e1a9b76ddc33f03 to your computer and use it in GitHub Desktop.
Save vojtasvoboda/aac55e1a9b76ddc33f03 to your computer and use it in GitHub Desktop.
Send mail with attachments in OctoberCMS
$email = '[email protected]';
$template = 'my.plugin::mail.recordform';
$templateParameters = ['site' => 'mysite.cz'];
$attachments = [];
foreach($record->images as $image) {
$attachments[] = $image;
}
Mail::send($template, $templateParameters, function($message) use ($email, $attachments)
{
foreach($attachments as $attachment) {
$params = ['as' => $attachment->getFilename()/*, 'mime' => $mime*/];
$message->attach($attachment->getLocalPath(), $params);
}
$message->to($email);
});
@gustallafer
Copy link

Hello, i've tried your code but i have a problem, i get only the last file attached to my email, even tough i'm uploading to the form more than one file, this is the code that im using to send the files to the emial.

`$attachments = [];
foreach($cliente->galeria as $image) {
$attachments[] = $image;
}

Mail::send('customdesign.damasdelite::mail.damasmessage', $vars, function($message) use ($attachments) {

  foreach($attachments as $attachment) {
    $params = ['as' => $attachment->getFilename()/*, 'mime' => $mime*/];
    $message->attach($attachment->getLocalPath(), $params);
  }
  $message->to('[email protected]', 'Damas de Elite');
  $message->subject('Nuevo Contacto');
});

`

Do you have any idea as to why i'm only getting one file? thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment