What is the location of the file for instructing PHP to include 'multipart' in emails? Is it PHP mailer? I'm looking for it, don't know where to look

hi guys,

We have a Amazon Linux server, which is using Postfix to send the emails. We need to go in and make a change to the PHP mailer (i believe?) in order for it to include 'multipart' when emails are sent out.

Do you know where I need to look and what the name of the file should be that needs to opened and have the multipart code added to it?

Who is Participating?

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

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.

Julian HansenCommented:
Please post the code you are using to create your emails.

The multipart is setup as part of creating your email message - when you create your email you specify the multipart sections - but to do it from scratch is a pain - better to use something like PHPMailer (https://github.com/PHPMailer/PHPMailer) and let it do the hard work.

Which is why to answer your question - we need to know how you are creating your emails.
YashyAuthor Commented:
Hi Julian,

We're basically calling this function in PHP:

error_reporting(E_ALL); ini_set('display_errors', '1');
        $email = $_GET['email'];
$subject = 'Email Subject';
//create a boundary for the email. This
$boundary = uniqid('np');
//headers - specify your from email address and name here
//and specify the boundary for the email
$headers = 'From: Contoso <no-reply@Contoso.com>' . "\r\n" .
   'Reply-To: Contoso <contact@Contoso.com>' . "\r\n";
 $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
//here is the content body
$message = "\r\n\r\n--" . $boundary . "\r";
$message .= "Content-type: text/plain;charset=utf-8\rContent-Transfer-Encoding: 7bit\r\n\r\n";
//Plain text body
$message .= "Hello,\nThis is a text email, the text/plain version.
\n\nRegards,\nYour Name";
$message .= "\r\n\r\n--" . $boundary . "\r";
$message .= "Content-Type: text/html; charset=utf-8\rContent-Transfer-Encoding: quoted-printable\r\n\r\n";
//Html body
$message .= file_get_contents('test.php');
$message .= "\r\n\r\n--" . $boundary . "--";
//invoke the PHP mail function
mail($email, $subject, $message, $headers);

Open in new window

However, our developer (codes in PHP) says that he didn't even think we're using phpMailer.  Nowhere in our code is there anything that calls the phpMailer function.
Julian HansenCommented:
phpMailer is a PHP library that you use instead of doing what you have above - it is much simpler to create and send emails.

What you have posted above is the raw PHP code for sending an email - nothing wrong with doing it that way if you know all the in's and outs of sending emails by code - if you are not 100% up to speed on the process then you should consider using a library like PHPMailer.

In fact the first consideration when sending out emails is to use a service provider that specialises in sending emails - you give them a list and and your email and they handle the sending and the, bounce backs, unsubscribes, white listing.

Managing an email reputation has become a very involved and tricky process - if you don't do it right you could find yourself blacklisted and unable to communicate with your client base.

So, my advice is
Move your email campaigns to a reputable campaign management service (Mailchimp etc).

If you can't do the above then plan b is to use a mail library like PHPMailer

In answer to your question though - there is no file that you put the boundary part in you do that in your php script. However, you are already doing this in your script - refer lines
12, 19, 22, 28, 33 of your listing above.

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
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

YashyAuthor Commented:
Thank you Julian. I haven't explained everything. We're using the Amazon SES service at the moment (something I'm slowly regretting).

But I appreciate your help on this.
Julian HansenCommented:
I haven't explained everything. We're using the Amazon SES service at the moment
Either way you should be able to use PHPMailer - if you have you cannot use an external service - although the latter should not be predicated on who you host with - but as you say you have not given all the details so maybe I am missing something.
Dave BaldwinFixer of ProblemsCommented:
There isn't any function in PHP to create 'multipart'.  You have to code it as part of the email message.  The link below shows several examples of doing that.

Dave BaldwinFixer of ProblemsCommented:
And PHPMailer is a good suggestion also.
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

From novice to tech pro — start learning today.