CarlEOgden's avatar

Laravel Send Mail::send - can both html & text be sent?

Hi

I've got my emails working as HTML but, to reduce on these direct emails being classed as spam, would like to add a text version of the message but it seems this plugin can either do text or html not both!

Or am I missing something?

Cheers Carl.

0 likes
7 replies
CarlEOgden's avatar

Hi

Thanks for that, for some reason my inherited code doesn't accept ->text so will do a bit more digging!

Will mark your answer as solved

Cheers Carl.

Sinnbeck's avatar

It goes in the mailable. Can you show it?

CarlEOgden's avatar

Hi

The actual bit of code that does the current emailing is:-

                    foreach ($email_addresses as $recipient_email_address) {
                        if (filter_var($recipient_email_address, FILTER_VALIDATE_EMAIL)) {
                            Mail::send('emails.letter', compact('subject', 'agent', 'branch', 'document'), function ($message) use ($reply_to, $subject, $agent, $recipient_email_address, $all_attachments) {
                                $message->to($recipient_email_address);
                                $message->from(env('MAIL_FROM_ADDRESS'), $agent->AgencyName);
								$message->subject($subject);
								foreach ($all_attachments as $attachments) {
									$message->attach($attachments);
								}
                                if (filter_var($reply_to, FILTER_VALIDATE_EMAIL)) {
                                    $message->replyTo($reply_to);
                                }
                            });
                        }
                    }
CarlEOgden's avatar

Hi

Just to let you know, the variable that is being compated "document", is an array with various fields including the html version of the email in a variable called "letter". I created another array called "text" and did strip_tags($document['letter']) and now when the email is sent, a text version is also sent with it!

Pure luck that I tried this and that it worked!

Thanks for your help Carl.

Please or to participate in this conversation.