0

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!

hakre
  • 193,403
  • 52
  • 435
  • 836
Gary Torres
  • 520
  • 7
  • 18

2 Answers2

0

Escape the XML so it's treated as text. For example "<" would be "&lt;"

0

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • I tried this approach and it crashes Im doing it like this: Mail::send('emails.xml_email', ['customer' => $customer], function($message){ $message->setContentType("text/xml")->to("recipient@email.com", '')->subject('New Customer!'); }); – Gary Torres Oct 21 '14 at 20:16
  • crash is not an error message. [How to get useful error messages in PHP?](http://stackoverflow.com/q/845021/367456) - please enable logging and then a concrete error message should help to say more. – hakre Oct 22 '14 at 12:21