This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

johnytributante17670
johnytributante17670

How can I send email in octoberCms with attachment? When I used this way to send email:

$mail = new Mail('newsletter', [
    'emails' => $emails,
    'subject' => $this->title,
    'data' => [
        'content' => $this->content,
    ]
]);
$mail->send();
return true;

I have image but I cant use this without $message function? Is there any way to send image with code above?

DMeganoski
DMeganoski

No, looking through the source, attachments are not mentioned anywhere in the mailer. It does not look for them in the data.

I would suspect that this expects you to do that in a callback as is the procedure in Laravel.

Instead of your approach, try this


$data = [
    'emails' => $emails,
    'subject' => $this->title,
    'data' => [
        'content' => $this->content,
    ]
];

\Mail::send('newsletter', $data, function ($message) use ($file_path, $file_name, $mime_type) {
    $message->attach($file_path, ['as' => $file_name, 'mime' => $mime_type]);
});
johnytributante17670
johnytributante17670

Please, can You told me what I do wrong? Now my email not send:

 $data = array('email' => 'thereIputmy@gmail', 'first_name' => 'Newsletter', 'from' => 'admin@gmail.com', 'from_name' => 'amin');
    $mime_type = 'mimes:jpeg,bmp,png';
    $file_path = $this->image->getPath();
    $file_name = 'file_name';

    \Mail::send('backend::newsletter', $data, function( $message ) use ($data, $file_path, $file_name, $mime_type) {
        $message->attach($file_path, ['as' => $file_name, 'mime' => $mime_type]);
        $message->to($data['email'])->from($data['from'], $data['first_name'])->subject('Welcome!');
    });

What should I write in mime_type if my attach will be always image for example. Now wit code aboce email not send.

Last updated

DMeganoski
DMeganoski

Well that would depend on what format the image is in. 'image/jpeg' is the mime for .jpg files. I think there may be a way to get this info out of the object, but I do not have time to go digging into the framework.

Here is a php function that you may be able to use to determine the mime type. if not, you should at least be able to figure out which one of them you need.

http://php.net/manual/en/function.image-type-to-mime-type.php

Does it send the email if you comment out the attachment?

Last updated

pramit.acharya2721921
pramit.acharya2721921

public $file;

public $file_path=['file'=>'System\Models\File'];
$file=Input::get('file_input');

Parse error: syntax error, unexpected '$file' (T_VARIABLE), expecting function (T_FUNCTION) for file path

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.