Multipart email template with broken links (PHP/Postfix)

hi guys,

I've got a major problem here. We have an email template that is Multipart.

When we call the PHP Mail function on our site (not PHP Mailer) to have this template sent, it uses from what I believe the Postfix function on our Linux instance to send the email from there via the Amazon SES service and then out. Sadly when doing it this way, the email template comes out with broken links.

When this email template has the original source file (attached test.php file) copied into something like Mailchimp or a service called Inkbrush, then it is previewed correctly and also it is received by the recipient in exactly the way we intend it to be received. I've included what it looks like when received by Mailchimp or previewed in it, along with the emailheaders when received from Mailchimp. The picture of what it looks like and what the email headers are have been attached.

We use Amazon Linux servers as our web servers. These servers use the Postfix service to then submit the emails via the Amazon SES service. We use a file called ‘Sendemailtest.php’ which uses the PHP Mail function to then call the ‘test.php’ file (which is the source of the email template) and sends the file via Postfix. The results are not as pretty sadly. I’ve attached the files as they appear when you send the same source via Amazon.

One thing we have noticed are the headers. With Mailchimp, you can see that in the headers section there is a line ‘Content-Type: Multitype/Alternative’ whereas the one in the Amazon servers appear as ‘Content-Type: text/html’.

We’re at a total loss. We are trying to conclude whether this is to do with PHP or whether it is the Postfix service causing this. Been at this for days now.

Thanks for looking into this guys.

Any questions you have, ask
test.php
Sendemailtest.php
Mailchipmp.jpg
Mailchipmp-Headers.txt
Amazon-servers.jpg
Amazon-headers.txt
LVL 1
YashyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
The first problem is that the PHP mail() function does not help you in creating a 'multipart' email.  You have to do that yourself and make it part of the message body.  The fact that MailChimp does part of it for you is misleading because they try to make their customer's email work properly.  The basic PHP mail() does not do anything to help you and the Amazon mail server is not going to do it either.

This is a simple but accurate article about creating multipart emails: http://webcheatsheet.com/php/send_email_text_html_attachment.php?print=Y

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve BinkCommented:
I agree with Dave Baldwin.  While your code appears to have what you need to make the multipart, you'd probably be better off using an email library to do it instead.  Even a small syntax error in your construction, and you could be debugging for awhile.

PHPMailer is a popular class for this.  I personally use an old class I found from Richard Hayes, edited for some better functionality.  I believe this is the original.
Dave BaldwinFixer of ProblemsCommented:
SwiftMailer http://swiftmailer.org/  is another recommended library.
YashyAuthor Commented:
After hours and hours...we've been told by Amazon to use their SES API instead. I'm going to post something else as I have a question about that, but it is PHP related. Thanks for helping out guys
Dave BaldwinFixer of ProblemsCommented:
You're welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.