I am trying to send emails with Laravel, and sending the email is working. I have a couple of stylesheets and images that are referenced using asset(). Problem is, when receiving the email all URL's is referencing 'localhost' instead of my domain causing the template to fall apart.
The asset() works great on all other views shown in a browser, even the email template. And the email I receive when sending from my local repo is working.
I have check that the .env value for APP_URL is correct, and I have tried to hard code the domain in config/app.php. I am using Forge and Envoyer.
Imported style sheets don't work with email let alone most CSS and almost no support for css3. You need to inline your styles and not reference a external style file. Unfortunately it's as simple as that. Generally tables are still used for columns etc. in emails as most email clients are not a full browser and security issues.
It's email styling 101 really. There are generators that take your template and try to set the styles as inline for you. Google it and you'll come up with some.
I am aware of the problems with styling emails. But I did this with my last project without any problems. If it was just the css references, I would have done it the old way, but when my images is behaving the exact same way, I am thinking that there might be something else wrong.
And, in development, using Homestead and Mailgun there are no problem with the stylesheets.
Okey, so I have now tried with a template with inline styling, and the css is working. But I still have the problem with image URLs. I even hard coded the complete URL, but when I send email to log the URL still points to localhost like this: http://localhost/assets/emails/images/email_logo.png
It should be reflecting the domain you were hitting when you generated the request, so if the php SERVER object contains localhost then that will be present in the path.
Try by setting up a domain name in your hosts file to point back to 127.0.0.1 and then hit your site through that domain.
Alternatively (and what I would do), don't use the asset helper, just hard code it or use a .env parameter
Everything is working great when I'm using Homestead but this happens when I upload my code to the testserver provisioned by Forge and deployed by Envoyer.
I have tried setting the the url by .env parameter and even hard coded the whole url, but it still replaces it with localhost.
I have tried setting the the url by .env parameter and even hard coded the whole url, but it still replaces it with localhost.
Then I suggest you are reading the evidence wrong. If you put <img src="http://mydomain.com/images/fancy.gif"> in your mail template then NOTHING should change that.
However, if you leave off the http:// part your browser will expect that the image is relative to your local machine. The localhost part will not be in the SOURCE for the message but the application you are viewing it with might assume it.
@Snapey I see your point. But even when I send to log, it shows me the localhost url.
@JoeDawson Yes, thats correct. I have tried restarting the worker (not using daemon on test server because of the framework restart). I even tried restarting the server. I see that there are others with the same issue when sending from queue, but not sure how to fix it.
@Snapey Its weird, but after restarting the server it seems to be working. The issue was when I updated the view to a full path, the queue would pull in the old version which still had the .env variable in it. Not sure why it did not fetch the correct version, as I was editing the file directly on the server, and made sure the changes was saved.