You are invited to Log in or Register a free Frihost Account!

PHP Sending Attachment Email

Trying to send an email attachment via PHP using this coding:

But am getting errors
Warning: fopen(./xxx.pdf) [function.fopen]: failed to open stream: Success in /home/medesign/domains/xxx/public_html/moreinfo.php on line 20

Warning: fread(): supplied argument is not a valid stream resource in /home/medesign/domains/xxx/public_html/moreinfo.php on line 22

Warning: fclose(): supplied argument is not a valid stream resource in /home/medesign/domains/xxx/public_html/moreinfo.php on line 24
The email was sent.

Any ideas?
Does the file exist and is it in the same directory as the php file ?
yes and yes Smile
It's not clear what the problem is, but first you have to get the fopen working. I would suggest trying other filenames, probably with a script that lets you type them in to save testing time. I am used to C, so I am unsure here. In C the rb would have to be in double quotes, but in PHP I'm pretty sure single quotes are ok, and I assume the arguments work the same. Remember the filename is case sensitive, and be sure there aren't any funny characters in there.
would you consider a "-" to be a funny character?
It could be a safe mode thing. If php's safe mode is on the owner of the directory needs to match the owner of the script.

Or it could be the 2nd parameter of fopen

Most of the file io functions should set the $errno and $errstr variables with an error number and error message. Maybe they hold some additional information
medesignz wrote:
would you consider a "-" to be a funny character?

I wouldn't think so, but if I created two files ./a-b.pdf and ./ab.pdf and only the second one opened, I would change my mind in a heartbeat.

@jmraker, useful posts about file open problems. Apparently the problem is not with safe mode, because the reported error is different. However, there could be versions of software that do not report the error properly. The second link, with error code SUCCESS, is a great example of the weird stuff that sometimes can happen. Your recommendation to display $errno and $errstr is a great idea.

I just noticed that the word Success does appear in the error message in the OP, so the problem might be something very similar to that second link! @medesignz, if you can get any file and access mode combination to work but some combinations don't work and it's still confusing, post a few examples of combinations that do and do not work. Maybe we can find and document the status reporting bug that seems to exist based on benjisimon's blog post.
Thanks for your help, I will look into this and post back my findings
Related topics
PHP: Feedback form issues.. help =P
China Against the Internet
Criterias for what to host?
Hi All I realy need your help... thanks in advance.. :)
WeBot, I need feedback!
Warcraft III play without disk
http header for POST
Using PHP's built in mail() to modify the from attribute.
Form Mail
How spammer earn money from spamming email?
emailing Via PHP
Sending Email from localhost
Help with php email
Need a Registration form PHP/Mysql with email confirmation
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

© 2005-2011 Frihost, forums powered by phpBB.