Making-Websites-With-October-CMS icon indicating copy to clipboard operation
Making-Websites-With-October-CMS copied to clipboard

Attachments

Open gustallafer opened this issue 7 years ago • 3 comments

Expected behavior

Hi Ivan i've been following your tuts on youtube and everything is great, the only problem i've encountered is with the email attachments. I've tried to research on the web without any luck and i was wondering if you could give a hand and tell me what i've been doing wrong.

I've the email form working great, all the other info is sent to my email without problem but not the image attachments. i will provide you with my files so you can look them over.

`<?php namespace CustomDesign\Damasdelite\Components;

use Cms\Classes\ComponentBase; use CustomDesign\Damasdelite\Models\Cliente; use CustomDesign\Damasdelite\Models\Categoria; use Input; use Mail;

class DamasForm extends ComponentBase{

public function componentDetails(){

return [
  'name' => 'Formulario de Damas',
  'description' => 'Agregar Damas'
];

}

public function onSave(){

$cliente = new Cliente();
$cliente->nombre = Input::get('nombre');
$cliente->slug = strtolower(Input::get('nombre'));
$cliente->poster = Input::file('poster');
$cliente->galeria = Input::file('galeria');
$cliente->correo = Input::get('correo');
$cliente->monto = Input::get('monto');
$cliente->celular = Input::get('celular');
$cliente->edad = Input::get('edad');
$cliente->categoria = Input::get('categoria');
$cliente->pais = Input::get('pais');
$cliente->piel = Input::get('piel');
$cliente->cabello = Input::get('cabello');
$cliente->ojos = Input::get('ojos');
$cliente->peso = Input::get('peso');
$cliente->altura = Input::get('altura');
$cliente->tipo_cuerpo = Input::get('tipo_cuerpo');
$cliente->vip = Input::get('vip');
$cliente->zona = Input::get('zona');
$cliente->depilada = Input::get('depilada');
$cliente->medidas = Input::get('medidas');
$cliente->fuma = Input::get('fuma');
$cliente->horario = Input::get('horario');
$cliente->promocion = Input::get('promocion');
$cliente->locacion = Input::get('locacion');
$cliente->servicios = Input::get('servicios');
$cliente->descripcion = Input::get('descripcion');
$cliente->plan = Input::get('plan');
$cliente->save();

$vars = [
  'nombre' => Input::get('nombre'),
  'slug' => strtolower(Input::get('nombre')),
  'poster' => Input::file('poster'),
  'galeria' => Input::file('galeria'),
  'correo' => Input::get('correo'),
  'monto' => Input::get('monto'),
  'celular' => Input::get('celular'),
  'edad' => Input::get('edad'),
  'categoria' => Input::get('categoria'),
  'pais' => Input::get('pais'),
  'piel' => Input::get('piel'),
  'cabello' => Input::get('cabello'),
  'ojos' => Input::get('ojos'),
  'peso' => Input::get('peso'),
  'altura' => Input::get('altura'),
  'tipo_cuerpo' => Input::get('tipo_cuerpo'),
  'vip' => Input::get('vip'),
  'zona' => Input::get('zona'),
  'depilada' => Input::get('depilada'),
  'medidas' => Input::get('medidas'),
  'fuma' => Input::get('fuma'),
  'horario' => Input::get('horario'),
  'promocion' => Input::get('promocion'),
  'locacion' => Input::get('locacion'),
  'servicios' => Input::get('servicios'),
  'descripcion' => Input::get('descripcion'),
  'plan' => Input::get('plan')
];

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

  $message->to('[email protected]', 'Damas de Elite');
  $message->subject('Nuevo Contacto');
});

} } ` As you can see i'm saving the info onto the database first and then sending it to my email. I know that to send and image you have to use the $message->attach() method but i cannot get the path of the image i always get an error.

Thank you in advance.

gustallafer avatar Aug 21 '17 23:08 gustallafer

What does your form look like. Does it have file request enabled? Something like: Form::open(['url' => 'foo/bar', 'files' => true]).

Did you check out this forum post, guy seems to be having same problem as you: https://octobercms.com/forum/post/sending-mail-with-attachment

ivandoric avatar Aug 22 '17 07:08 ivandoric

Hi Ivan, i tried the solution you gave me and works fine. Now i need to attach a few files if you see the code i have two Input::file fields, one is for a single pic and the other one is for multiple pics, how can i have the two fields under the same variable.

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

$message->to('[email protected]', 'Damas de Elite'); $message->subject('Nuevo Contacto'); $message->attach(Input::file('poster'), ['as' => 'poster.jpg'], Input::file('galeria[]'), ['as' => 'galeria[].jpg']); });`

could it be something like that???

gustallafer avatar Aug 22 '17 12:08 gustallafer

I don't know, I never had a case like that. Why don't you just try it out and see if it works.

ivandoric avatar Aug 24 '17 06:08 ivandoric