Swiftmailer question

If I want to use Swiftmailer to send a newsletter and I build the look of the newsletter as a php page. How should I include this in the code?
I think I did it like this before:

$webmail = file_get_contents('http://www.website.com/webmail/webmail_2014.php');
$message->setBody($webmail, 'text/html');
$result = $mailer->send($message);

I have all the From, To, Sender aso there as well.
But the code doesn’t seem to include my page in the body when trying to send.
Is there another way to do this or a better way that will work?

Hi,

There is a basic example in the swiftmailer documentation http://swiftmailer.org/docs/messages.html see if that helps you?

But I can’t find anything about adding a webpage as the content there. I would like to add a link to something like this: http://www.website.com/webmail/webmail_2014.php

What’s the value of $webmail immediately after the call to file_get_contents? Check to make sure it’s what you expect. Also, what exactly is in the body of the email that you receive?

Nope. Those three lines you posted look fine, which means there’s something else in play that’s causing the problem.

Well, the content that is written after file_get_contents is a web page and it looks fine on screen.
In the e-mail I get nothing. Just a blank e-mail. But, when I tried to send it to Mac Mail I could see that the beginning of the text was listed in the preview field. Something like the image below:

Hmmm. I just tested the following:


$text = 'This is just a test';
$message->setBody($text, 'text/html');
$result = $mailer->send($message);
 

That one worked fine. At least I received a text message in my inbox.
So, there must be something wrong with the way it’s including a web page.

Maybe it’s not the right way to use file_get_contents to include a web page?

There are possible reasons why that call might fail, yes. Which is why I suggested that you check the value of $webmail immediately after the call to file_get_contents. Make sure the call succeeded and that you got the value you were expecting.

Any chance that the emails you’re checking with disallow HTML? Some email services will allow you to view the email’s source. Try that and see if the HTML is in there.