Homicity / laravel-mandrill

2 stars 3 forks source link

how to add mail content and attachment #3

Open ubiquitant-01 opened 5 years ago

ubiquitant-01 commented 5 years ago

you havent mentioned how to add mail content and attachment in your usage..can you please help

mahmoud-birdsol commented 5 years ago

@Lyonel-Homicity please correct me if I am wrong but I believe you could use ->globalMergeVars($data)

@Lyonel-Homicity also can we please this part to the read me

I believe you could just call any of those variables as a method

return [
            'subject'           => '',
            'from_email'        => config('mandrill.from_email'),
            'from_name'         => config('mandrill.from_name'),
            'to'                => [[
                'email' => '',
                'name'  => '',
                'type'  => 'to',
            ]],
            'important'         => false,
            'merge'             => true,
            'merge_language'    => 'handlebars',
            'global_merge_vars' => [],
            'merge_vars'        => [],
            'tags'              => [],
        ];
Lyonel-Homicity commented 5 years ago

@mahmoud-birdsol that is 100% correct. This package uses the mandrill php package and you can call any of their Message-Calls API as a method. You can refer to their API documentation for this.

https://mandrillapp.com/api/docs/messages.php.html#method=send

The global verge vars are used to populate dynamic content on your selected template.

To add an attachment you can call the attachments method and pass an array of attachments like this

array(
    array(
        'type' => 'text/plain',
        'name' => 'myfile.txt',
        'content' => 'ZXhhbXBsZSBmaWxl'
    )
)

Please let me know if this help at all.

ubiquitant-01 commented 5 years ago

im using the below code for attachment but its not working

                    $cvattachment= file_get_contents(request()->file('file')->getRealPath());
        $cvattachment_encoded = base64_encode($cvattachment); 

        $attachfile= "";

        if(request()->file){
            $attachfile= array(array('type'=>request()->file('file')->getMimeType(),'name'=>request()->file('file')->getClientOriginalName(),'content'=>$cvattachment_encoded));

        }
        else
        {
            $attachfile= array();
        }

        $arr = array(array('name'=>'FormContent','content'=>$this->array_to_html($mail_content)));

        Mail::mandrill()
        ->to('xxx@xxxx.com')
        ->name('xxxxxx')
        ->fromEmail('reach@xxxxx.com')
        ->templateName('xxx-new-website-contact-us-form')
        ->fromName('XXXx')
        ->merge(true)
        ->merge_language('mailchimp')
        ->global_merge_vars( $arr )
        ->attachments($attachfile)
        ->tags(['Testing'])
        ->subject('Contact enquiry from website')
        ->send();