I want to send an Email that has XML as content. I've created a blade view for this called xml_email.blade.php
to which I pass the variables that conform the email.
My xml_email.blade.php
looks like this:
{{ '<'.'?'.'xml version="1.0" encoding="UTF-8"?>' }}
<customer>
<contact>
<name part="full">{{$customer->name}}</name>
@if($customer->allow_phone == true)
<phone>{{$customer->phone}}</phone>
@endif
<email>{{$customer->email}}</email>
</contact>
</customer>
And I am sending it like this from a controller
Mail::send('emails.xml_email', ['customer' => $customer], function($message){
$message->to("recipient@email.com", '')->subject('New Customer!');
});
The email gets sent however is not in XML format and all the tags are missing.
Is there a way to change the Mime Type of the email to text/xml
or to keep all the XML tags when sent?
Thanks!
Escape the XML so it's treated as text. For example "<" would be "<"
You want to set the content-type of your email message.
In Laravel, the $message
is documented to be a subtype of Swift_Message
( reference ), therefore
$message->setContentType($contentType);
should do it. So setting it to " text/xml
" might already do it, see Swift_Mime_SimpleMimeEntity::setContentType
, which is the base classe of Swift_Message
with the method implementation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.