alternative program that allows attachments

Working with eCommerce store where mail() is used, 'thank you for your purchase email' when they make purchase

Sometimes customers are emailed a pdf file

Looking for alternative  to php mail() that allows attachment file

I can not use phpmailer because gmail has many restrictions (I was only allowed 25 emails a day, with gmail blocking some emails)

Please do not suggest any answer involing phpmailer
Who is Participating?
grahamnonweilerConnect With a Mentor Commented:
You can use the PHP mail() function to send attachments, but you have to create the message in "multi-part mime message" format.

Meaning, the mail() function allows you to specify:

who to send mail to
the subject line
the message body
the headers

To create and send a multi-part mime message (ie. a message with attachements) then you will have to manually (programmatically) create the "headers" and the "message body".

The actual attachment will have to converted to base64 encoded textual content, that will be appended to the message body.

The message will have to have a unique identifier, that is stated in the headers as the "boundary" and then used within the message body with special markers to allow the receiving MTA to decode the attachment.

A rough example of how to do this with php (please note this is meant only as an example):


$mime_boundary=md5(time()); \\ unique boundary marker for your multi-part message
$mime_type="application/pdf"; \\ change this to the correct mime type for your file

\\ $filename = the name of your attached file
\\ $document = the path to the actual file you wish to attach
\\ $sendto = the eail address you are sending to
\\ $textmessage = the textual part of your message

$mlsubj="This is my subject"; \\ replace as needed

$headers="To:Someone<>\n"; \\ replace these as needed
$headers.="From:MyEmail<>\n"; \\ replace these as needed
$headers.="Date: ".date("r")."\n";



$sendmessage=mail($sendto, $mlsbj, $msg_body, $headers);

Phpmailer is not the problem. Phpmailer is just an alternative to mail() but both send email through an SMTP server the same way because there is really only one way to send emails. Using mail() is like having person A write a letter for you and put it in the mailbox. Using phpmailer or any alternative is like having person B write the letter an put it in the same mailbox. Both ways, they still get sent through the post office and its still the same letter.

You need to get an smtp server set up and set up spf rules to reduce the chances of your mail getting blocked. Read my article on email delivery.
Do you have a monthly budget for this project? If you can spare $15 a month then you can set up your own smtp server in a vps hosting account.
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

gr8gonzoConnect With a Mentor ConsultantCommented:
graham's code will work to send attachments, but you are still doing the same thing as PHPmailer and mail(), so you are still going to experience the same problems if you are having issues with emails getting blocked.

When gmail or any other provider blocks messages, it does not care about whether you used phpmailer or mail() or Outlook or Thunderbird or anything else to send the message. All the mail server cares about is:

1. The contents of the email: Does it look like spam, or does it have any viruses?
2. The sender's address: Is the sender's IP address in a blacklist or is there any reason to think the sender is a spammer?

I wrote an article a long time ago with different reasons for blocked email and how to fix it:

What you are experiencing is likely due to reasons #5 and #6. Changing your mailing code / script is not going to help you. To fix #5 and #6, you need to change the mail server you are using to send out email. You need a mail server that will be dedicated to your use, and then you need to set up SPF to reflect your new mail server.

You can get a cloud-based virtual system from Atlantic here:

The smallest plan should be more than enough for a mail server for you.

Let's say your domain is You would set up a hosting plan with Atlantic or another VPS provider - preferably one that gives you your own cPanel set-up to make administration easy. Then you can set up your own email account, and use the server to send your email.

Then you set up your SPF record in your DNS for and tell it that your new server from Atlantic (or wherever) is the only one that is authorized to send out emails from addresses that end with This is how SPF works - it adds legitimacy to the messages you send.

This site can help you understand and set up SPF:
Ray PaseurConnect With a Mentor Commented:
Suggestion: Why not just store the PDF on the server file system and send the client a link to open/download the PDF?  Poof!  No attachment problems, and the client will never have to call you saying, "I accidentally deleted my PDF - can you send me another?"

Plus 2 for what Gr8gonzo wrote.

Best to all, ~Ray
rgb192Author Commented:
thank you for suggestions on attachments
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.