Portal Home > Knowledgebase > Articles Database > PHP mail with attachment


PHP mail with attachment




Posted by pwalters09, 01-14-2010, 01:39 AM
Hi, I need to get a PHP mail script of some sort with the ability to send the attachment to my email address. My use for this is, I want to run the script automatically via a file include every 15 minutes to automatically backup my database and email it to me, just in case anything goes wrong with my server. The code I have so far is just a backup script which uploads the file to the server in a directory called /backups/ Can anyone help with this, I have already added the unlink function to delete the file from the server once it has been sent, so all I need is the script to email me the file... Any help is appreciated... Thanks

Posted by mattle, 01-14-2010, 09:17 AM
For easy attachment handling, I recommend Pear's Mail::MIME module: http://pear.php.net/manual/en/packag...me.example.php

Posted by jaman9, 01-14-2010, 03:15 PM
I have used the above method without problems. You will need to modify the settings in $smtp_config to suit your needs though. It the email header details are incorrect, then it may be down to the configuration of the mail server/MTA. Not sure about the blank subject though. Also, which version of Zend Framework are you using? Regards,

Posted by warddr, 01-14-2010, 03:24 PM
I use this: http://sourceforge.net/projects/phpmailer/: edit: this is the correct link: http://sourceforge.net/projects/phpm...1.zip/download It works fine. You can even use gmail smtp server. I do the same thing as you do, only I do it daily. Last edited by warddr; 01-14-2010 at 03:32 PM.

Posted by abushahin, 01-14-2010, 03:31 PM
Hey im with a free webhost they dont allow mass mailers, any manual php code that can do similar things?

Posted by larwilliams, 01-14-2010, 03:49 PM
I can second this. phpMailer is very simple and easy to use with sending attachments. The only comment I need to disagree with is the one about using an external SMTP server to send mail. Many hosts will not allow this (for spam reasons). If you are not sure, please contact their support department to confirm.

Posted by pwalters09, 01-14-2010, 04:37 PM
Thanks guys will check that one out and report back to let you know if it works for me (I do not use any control panel, just a basic install with ftp/httpd/mail/php/phpmyadmin @ abushahin Please do not hijack threads, if you have a problem please create a new topic, but to help you out this should work Last edited by pwalters09; 01-14-2010 at 04:49 PM.

Posted by mattle, 01-14-2010, 05:40 PM
I thought sending an attachment was part of the original spec...

Posted by pwalters09, 01-14-2010, 06:07 PM
yes it is lol I just wrote the above code quickly to help the user who hijacked my thread, that above is just a quick way to mass spam (email)

Posted by mattle, 01-14-2010, 06:15 PM
lol...whooops...read your code, not your text

Posted by JBapt, 01-14-2010, 06:28 PM
we use phpmailer and its great. Don't use the native php mail function and use an existing smtp account through a smtp library. It's the right way to go!



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
RKhunter (Views: 606)