Swiftmailer message headers appearing in message and not being processed - swiftmailer

This script is designed to attach a PDF to a HTML email. The email itself sends fine, and I can see that the attachment is sending too, however my problem is that the email headers do not seem to be getting processed, and so I can see the headers in the email body itself and my attachment shows in the email body as a base64 encoded string.
$attachment = Swift_Attachment::newInstance(file_get_contents($this->pdf), ucfirst($type) . '-VIP-membership-welcome-pack.pdf', 'application/pdf');
$this->message
->setSubject($this->subject)
->setBody($this->body, 'text/html')
->setTo([$orderDetails['EmailAddress']])
->setBcc(['support#harpoonmedia.co.uk', $this->defaultHeaders['to']])
->setFrom([$this->defaultHeaders['from']]);
$this->message->attach($attachment);
I've tried adding the file using Swift_Mailers ::fromPath method, and got the same response - when there is no attachment I see the HTML is added to the email correctly.
Here is an example of the output (truncated)
--_=_swift_v4_1417539844_a449b32848d1edc3be2f0d67f968c81675770047_=_
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type=3D"text/css">
#hkemail #outlook a{padding:0;}
#hkemail body{width:100% !important;-webkit-text-size-adjust:100%;-ms-text-size- adjust:100%;margin:0;padding:0;}
#hkemail .ExternalClass{width:100%;}=20
#hkemail .ExternalClass,.ExternalClass p,.ExternalClass span,.E=
xternalClass font,.ExternalClass td,.ExternalClass div{line-height:100%;}
#hkemail .bodytbl{margin:0;padding:0;width:100% !important;}=20
#hkemail img{outline:none;text-decoration:none;-ms-interpolatio=
n-mode:bicubic;display:block;}=20
#hkemail a img{border:none;}
That's a piece of the HTML body that is output in the message, and heres some of the attachment that is output in the message body:
--_=_swift_v4_1417539844_a449b32848d1edc3be2f0d67f968c81675770047_=_
Content-Type: application/pdf; name=Gold-VIP-membership-welcome-pack.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=Gold-VIP-membership-welcome-pack.pdf
JVBERi0xLjQNJeLjz9MNCjQgMCBvYmoNPDwvTGluZWFyaXplZCAxL0wgMTE3ODY4MC9PIDYvRSAx
MTE5NzczL04gMS9UIDExNzg0ODEvSCBbIDEzOTYgMjY0XT4+DWVuZG9iag0gICAgICAgICAgICAg
DQp4cmVmDQo0IDU1DQowMDAwMDAwMDE2IDAwMDAwIG4NCjAwMDAwMDE2NjAgMDAwMDAgbg0KMDAw
MDAwMTcyMCAwMDAwMCBuDQowMDAwMDAxOTk0IDAwMDAwIG4NCjAwMDAwMDI0MjcgMDAwMDAgbg0K
MDAwMDAwMjU4NCAwMDAwMCBuDQowMDAwMDAyNjE4IDAwMDAwIG4NCjAwMDAwMDU2OTggMDAwMDAg
and obviously this carries on for ages.
Any help much appreciated thank you!

I had this same problem and realised I was using a DEV version - Swift-5.3.1-DEV (therefore possibly unstable).
After downgrading to the latest stable version Swift-5.3.0, I can now see this issue gone.
I did not use Composer to install the latest stable, but instead found myself using the ZIP from SwiftMailer's GitHub account. This version is the DEV version, so make sure you're getting the latest stable release: https://github.com/swiftmailer/swiftmailer/releases
Hope this helps.

Related

CURL on dell support website - access denied

I am trying to reach dell support website to be able to check server's warranty from the terminal.
I have found this link for curl, but it returns me access denied error.
curl https://www.dell.com/support/home/uk/en/ukdhs1/product-support/servicetag/$(dmidecode -s system-serial-number)/warranty?ref=captchasuccess
output:
<HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>
You don't have permission to access "http://www.dell.com/support/home/en/en/ukdhs1/product-support/servicetag/XXXXXX/warranty?" on this server.<P>
Reference #18.3fd86b68.1653307511.316d4d5
</BODY>
</HTML>
I have tried many simmiliar links and different machines, the output seems to be always same.
Does anybody have an idea how to be able to access dell support page via curl,wget, or simmilar command?
I am able to check warranty manually via browser.
I can go to https://www.dell.com/support/home/en-us
and put serial number in "identify my product" tab. after clicking "view details" i can see the warranty expiration.
########################################################################
EDIT:
curl is now working:
curl --header 'user-agent: Chrome/1337' https://www.dell.com/support/home/sk-sk/product-support/servicetag/<serial-number-here>/overview
or
curl --header 'user-agent: Chrome/1337' https://www.dell.com/support/home/uk/en/ukdhs1/product-support/servicetag/$(dmidecode -s system-serial-number)/warranty
The another problem is that output of this curl is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Challenge Validation</title>
<link rel="stylesheet" type="text/css" href="/_sec/cp_challenge/sec-3-6.css">
<script type="text/javascript">function cp_clge_done(){location.reload(true);}</script>
<script src="/_sec/cp_challenge/sec-cpt-int-3-6.js" async defer></script>
<script type="text/javascript">sessionStorage.setItem('data-duration', 30);</script>
</head>
<body>
<div class="sec-container">
<div id="sec-text-container"><iframe id="sec-text-if" class="custmsg" src="/_sec/cca/esupp/index.htm"></iframe></div>
<div id="sec-if-container">
<iframe id="sec-cpt-if" class="crypto" data-key="" data-duration=30 src="/_sec/cp_challenge/ak-challenge-3-6.htm"></iframe>
</div>
</div>
</body>
</html>
I have tried to check it via web browser and to pass that challenge validation I had to wait up to 30 seconds, and then I was redirected to the desired page.
Is it possible to somehow setup curl or wget to actively display the webpage content for like 40 seconds ? Or do I have to to rather use elinks to achieve this goal ? And does elinks have an option to customize header with user-agent parameter ?
EDIT2:
I have tried to install elinks and created ~/elinks/elinks.conf with this content:
set protocol.http.user_agent = "Chrome/1337"
But it again provides me output access denied , most likely because the user agent header is not the last header
that's a really strange server... 3 issues here,
#1: they run on a user-agent whitelist, and curl is not on their whitelist. you can use the custom user-agent chrome/1337 to pass their useragent whitelist (and just saying "chrome" doesn't cut it, it must be chrome/A-NUMBER, but that number can be fake, it doesn't have to be a real chrome release number)
#2: that broken server only accepts requests where the very last http header is the User-Agent header. unfortunately for you, curl by default sends the Accept: */*-header as the very last header, with the user-agent header being the second-to-last-header this means that you can't use the --user-agent switch to get past the agent whitelist either, you must add the user-agent header with the --header arguments (which puts the header last, fortunately for you)
#3: that url ?ref=captchasuccess probably means that this is a redirect AFTER completing a captcha, meaning the captcha-completed data is part of your cookie session, which means you'll probably have to clear a captcha, then copy your cookie session to curl, then run the request..
anyway, for the user-agent issue, try
curl --header 'user-agent: Chrome/1337' https://www.dell.com/support/home/uk/en/ukdhs1/product-support/servicetag/$(dmidecode -s system-serial-number)/warranty?ref=captchasuccess

How can I get the token to use the REST API in a user and password protected instance of NiFi?

I have a NiFi instance running on a Docker container and, and I'd like to get some information about it through its API. To do so, I have followed the steps indicated here: https://community.hortonworks.com/questions/96383/how-to-get-the-access-token-by-invoking-nifi-rest.html, using this command:
curl 'http://<my_nifi_ip>:<my_nifi_port>/nifi/nifi-api/access/token' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'username=<my_user>&password=<my_password>' --compressed
But, when launching this command, it redirects me to the login page of NiFi
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved here.</p>
</body></html>
How can I solve my problem to get the token?
Thank you for your help. Regards.
The URL in the curl command needs to be 'https' instead of 'http', and the path is a little bit off and should not have the /nifi in front of /nifi-api.
You can cross-check against the curl command in the community post you linked to which I think has the correct command.

Magento 2 blank page but not empty

I am developing a Magento 2.3 site which was working but has stopped. When I try to get a page up, I get a blank screen. Although it looks empty, it actually contains a little content:
<!doctype html>
<html lang="en">
<head >
<meta charset="utf-8"/>
<meta name="description" content="Blah Blah"/>
<meta name="keywords" content="More blah blah"/>
<meta name="robots" content="INDEX,FOLLOW"/>
<title></title>
<link rel="icon" type="image/x-icon" href="http://www.magento2.domain/pub/media/favicon/stores/1/3-ladies-bg.jpg" />
<link rel="shortcut icon" type="image/x-icon" href="http://www.magento2.domain/pub/media/favicon/stores/1/3-ladies-bg.jpg" />
<link href='https://fonts.googleapis.com/css?family=Prosto+One' rel='stylesheet' type='text/css' />
<!--xxxabb2c66c7681e8f658-->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxx-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-131267613-1');
</script> </head>
<body data-container="body" data-mage-init='{"loaderAjax": {}, "loader": { "icon": "http://www.magento2.domain/pub/static/version1551796553/frontend/_view/en_GB/images/loader-2.gif"}}' class="cms-index-index page-layout-1column">
</body>
</html>
If I look in the system log, I see the following errors:
[2019-04-30 21:24:48] main.INFO: Broken reference: the 'theme.active.editor' element cannot be added as child to 'after.body.start', because the latter doesn't exist [] []
[2019-04-30 21:24:48] main.INFO: Broken reference: the 'logger' element cannot be added as child to 'after.body.start', because the latter doesn't exist [] []
I've enabled error logging but I get nothing. Can anyone help?
Alternatively, can somebody point me to a good map (or similar) of how magento 2 builds a page so I can try and track down the error.
I have tracked down the issue to a problem with pub/generated/metadata/global.php. Even regenerating it causes the same problem. If I delete the file everything seems to work ok. I confess to not understanding why!
I now avoid this by not running bin/magento setup:di:compile. I simply run php bin/magento setup:static-content:deploy.
I think this error is due to a broken reference in some XML file. You have not mentioned in which page you are getting this error. But you can trace it as below:
First of all, rename your default.xml from below path:
app/design/frontend/Vendor/Theme_name/Magento_Theme/layout/default.xml
Flush all the cache and check(php bin/magento cache:flush)
If you don't find anything then rename your page(homepage, listing, detail page, etc) related file.
For example, if you are getting this error on the homepage then rename cms_index_index.xml.It can reside in your theme or any custom extension.
Hopefully, this information can help you with the issue.
remove everything under generated folder except .htaccess file
I am using Magento 2.3.2 version. In production mode generating generated directory using setup:di:compile is working fine. However, in developer mode doing same is making all pages on frontend blank but not empty (content inside body tag is empty) so I deleted the generated folder and let it be created automatically as I access the site pages. Doing this resolved the issue for me.
Just go to Magento directory and then delete file generated by di:compile is path :-
magento\generated\metadata\global.php delete this file then after refersh your page.
This is temporary solution for this error in local server.

Python 3.x XAMPP UTF-8 encoding

I am making a small python driven web page. It works fine, but it is Windows-1250 encoded. If I put meta tag for UTF-8 encoding to support our special characters ČŠŽ I get question marks.
If I put html code in simple .html document it shows fine. But in .py file it is not working OK.
print("content-type: text/html\n" )
print('<html>')
print('<head>')
print('<title>Python page</title>')
print('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />')
print('</head>')
I checked httpd.conf and added
#UTF 8
AddDefaultCharset utf-8
but it does the same as meta tag.

wkhtmltopdf outputs garbled text

I just installed the latest static build of wkhtmltopdf-amd64 (0.12.3). On any html page I convert to PDF, the text appears as solid squares.
Example of google's homepage as PDF:
[acoder#box bin]# ./wkhtmltopdf-amd64 http://google.com goog.pdf
Or, here's an even simpler HTML source doc:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The HTML5 Herald</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">
</head>
<body>
<p>Hello world.
<table><tr><td>I am a table</td></tr></table>
<pre>formatted</pre>
</body>
</html>
Output:
What could be causing this?
This was due to a missing dependency, urw-fonts. After that was installed, converted text is readable.
For clarity & documentation on a minimal install of EL7:
Grab the wkhtmltopdf-amd binary and unpack to a temporary location.
Install dependencies: yum install libXrender libXext fontconfig urw-fonts
Test the binary with wkhtmltopdf-amd -V - this should print the version (0.12.3 as of today).
Next test that it converts documents as expected. wkhtmltopdf-amd http://google.com googlehomepage.pdf
If the output PDF looks good, then copy the binary to /usr/bin and call it done.

Resources