• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

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
0
rgb192
Asked:
rgb192
3 Solutions
 
gr8gonzoConsultantCommented:
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.
0
 
gr8gonzoConsultantCommented:
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.
0
 
grahamnonweilerCommented:
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<someone@company.com>\n"; \\ replace these as needed
$headers.="From:MyEmail<me@company.com>\n"; \\ replace these as needed
$headers.="Date: ".date("r")."\n";
$headers.="MIME-Version:1.0\n";
$headers.="Content-Type:multipart/mixed;boundary=\"".$mime_boundary."\"\n";

$msg_body="--".$mime_boundary."\n";
$msg_body.="Content-Type:text/plain;charset=iso-8859-1\n";
$msg_body.="Content-Transfer-Encoding:7bit\n\n";
$msg_body.=$textmessage."\n\n";

$msg_body.="--".$mime_boundary."\n";
$msg_body.="Content-Type:".$mime_type.";name=\"".$filename."\"\n";
$msg_body.="Content-Transfer-Encoding:base64\n";
$msg_body.="Content-Disposition:attachment;filename=\"".$filename."\"\n\n";
$msg_body.=chunk_split(base64_encode($document))."\n\n";
$msg_body.="--".$mime_boundary."--"."\n\n";

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

?>
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
gr8gonzoConsultantCommented:
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:
http://www.experts-exchange.com/Software/Internet_Email/A_1222-16-Tips-to-Improve-Email-Delivery.html

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:
http://www.atlantic.net/cloud-hosting/cloud-server-pricing.html

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

Let's say your domain is rgb192.com. 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 rgb192.com 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 @rgb192.com. This is how SPF works - it adds legitimacy to the messages you send.

This site can help you understand and set up SPF:
http://www.openspf.org/
0
 
Ray PaseurCommented:
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
0
 
rgb192Author Commented:
thank you for suggestions on attachments
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now