alternative program that allows attachments

Posted on 2012-08-17
Last Modified: 2012-09-01
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
Question by:rgb192
    LVL 34

    Expert Comment

    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.
    LVL 34

    Expert Comment

    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.
    LVL 16

    Accepted Solution

    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);

    LVL 34

    Assisted Solution

    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:
    LVL 107

    Assisted Solution

    by:Ray Paseur
    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

    Author Closing Comment

    thank you for suggestions on attachments

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now