Announcement

Collapse
No announcement yet.

sending email with image attachment driving me crazy

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • sending email with image attachment driving me crazy

    hi guys, i really tried for 2 days continuously before creating this thread,

    simply, i have a single record form that has one image (filename) field name {image2} - the subfolder is {id}

    i creted a button to send the values of this form by email with this field as attachment... i think my problem is the path that i am including in the attachment, in production, i have the exact path like this: http://domain.com/project/_lib/file/img222/image.jpg - this works in browser ok

    if i add in the email code this

    Code:
    $mail_attachments =	'http://domain.com/project/_lib/file/img'.{id}.'/'.{image2};
    it throws this error

    Code:
    fopen(http://domain.com/project/_lib/file/img222/) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden
    i tried many many many paths, including with and without http, tried www, tried interal path of the server like

    Code:
     /public_html/domain/project/_lib/file/img.{id}.'/'{image2}
    tried with concatinate (.) and without, tried with double quotes " " and ' ' , tried with array and direct single file in the code all useless

    sometimes the page stop opening, sometimes after clicking the button to send it loops then stops without response or any error

    here are more tests i tried: http://www.scriptcase.net/forum/show...ll=1#post26230


    what drives me crazy even more, that if i put the path EXACT like:

    Code:
     http://domain.com/project/_lib/file/img222/image.jpg
    it works!! and it sends this exact file as attachment normally with the email, so i think it is not the permission or the fopen issue which i googled it a lot without success.. but when trying to change to variable/fields... starts this strange issue

    any idea or a hint to make this work is highly appreciated....note, i have this field not required in the form, so sometimes is not there, should there be a check for if it is empty as well or not!?


    Mike
    Last edited by MikeDE; 08-27-2014, 04:12 PM.

  • #2
    I think its the way you are specifying the path - I think SC is expecting an internal path as opposed to an external path. That's not to say it shouldn't be able to cope in some way. I actually set a global variable pointing at the necessary folder (in app_login's onApplicationInit event). The path differs if it's the production site or the dev site, so I check the port it is running on (very rudimentary, I know) to check, and then set the path accordingly:

    Code:
    // Identify if running on Prod or Dev environment
    if ((substr($_SERVER['HTTP_HOST'],-4) == '8083') OR (substr($_SERVER['HTTP_HOST'],-4) == '8098')) {	// Current Port?
    	[prod] = FALSE;
    	[fp] = "../../../file/doc/timesheets/";
    
    } else {
    	[prod] = TRUE;
    	[fp] = "../_lib/file/doc/timesheets/";
    }
    For you the paths might be:

    Code:
            [fp] = "../../../file/";
    
    Or
    	[fp] = "../_lib/file/";

    Then (wherever you need it) you can use:

    Code:
    $mail_attachments =	[fp] . 'img'. {id} . '/' . {image2};
    Or - if ports / environments are not an issue - then ignore above and just change the assignment where it is so it reads:

    Code:
     '../_lib/file/img'. {id} . '/' . {image2};
    Or perhaps (or whatever)...

    Code:
     '../../../_lib/file/img'. {id} . '/' . {image2};

    Comment


    • #3
      hi adz1111, thanks for the effort, i'm going to try it now and let you know
      one thing please, do you mean i have to put these dots like this '../_lib/file/img'
      or i have to replace them with actual values?

      Comment


      • #4
        No - you actually use the dots - ".." means the parent directory regardless of it's name. Of course you can replace them with actual values if you prefer.

        So for example, if at a command prompt and you do a "cd /adam/folder1", you end up in /adam/folder1

        If you then do a "cd .." you end up in /adam

        ".." is a relative form allowing you to backtrack up the folder tree without knowing or specifying the actual name of the parent folder - works for Windows and linux.

        Re production or dev, it's possible that the final paths are different between the 2 environments (one may be longer / shorter than the path in the other). So I would experiment with just ../ first, and if no good try ../.. and so on. Just remember that success with one in dev may need experimentation in the resulting prod environment.

        If the paths are the same in terms of number of folders then ".." is helpful as it doesn't matter if the number of folders is the same but the folder names differ.

        Comment


        • #5
          hi again adz1111 and thanks for your time.

          i tried:

          '../_lib/file/img'. {id} . '/' . {image2};

          and

          '../../../_lib/file/img'. {id} . '/' . {image2};

          if put in an array, it throws an error (unexpected and if i put as individual attachment file the page loads but when sending it takes long then a blank page!

          as i said before, if i put a direct link to static file like this:
          http://domain.com/project/_lib/file/img111/image.jpg
          it works! and that static image is going by attachment! remains the path to adjust!?

          do you think it has do something with the subfolder? should i remove it in the upload form and the grid then upload a new one to the root of file/ then try? this will make me change a lot of things though!

          what i put in this field is SC asks subfolder: i put: {id}

          should it be /{id} for the upload form and the grid?

          really irritating, started to be personal

          Comment


          • #6
            Hi itsme3

            The path should be from the web server's document root I believe. You've done 1 and 3 layers, so also try 2 (../../), or 4 - or explicitly use "/opt/Netmake/v8/_lib/file.........." or whatever it is in your case. Remember, I believe its the internal path you need not the external http one - yes the external one works in a browser, but that's not how the file location is resolved as far as the app goes....

            It may also be the way SC parses the string - maybe try building the path string first and then assigning it - then you can examine it to see if the string is built correctly, as well as experiment on the number if ../'s to use:


            Code:
            $docpath = 'http://domain.com/project/_lib/file/img'.{id}.'/'.{image2};
            
            $mail_attachments =	$docpath;
            Just a thought
            Last edited by adz1111; 08-29-2014, 08:08 AM.

            Comment


            • #7
              thanks adz for the reply, yes i tried 2 layers too, i tired thins you will never imagine!
              fine, your theory of paths that are from the internal server pathing i think that so, so now will try to make it like from before the /public_html... will check with my host and see what is the /usr/bin full patch of the server

              however, there is something else, if i use the $mail_attachment = '/../../../../..{image2}' --this way, if the image2 field is empty (it is not required) then will have error as well

              and if i put it in an array
              $mail_attachment = array ( '/../../_lib/file/img.{id}.'/'.{image2};

              );

              this is wrong as well, there should not be a ; after the image, only after the array closing tag... and if removed, there is more than a single quote in the attachment line, how the php will know that this array line is over? so it will give error as well


              so i don't know which one should i focus to use (even if found the correct path) because this file is not required in the form, hence it may be left empty and hence it will not be included in the email attachment in case was not there! hope you understood what i mean

              Comment


              • #8
                Wow - a few things there...

                however, there is something else, if i use the $mail_attachment = '/../../../../..{image2}' --this way, if the image2 field is empty (it is not required) then will have error as well
                Regarding if empty why not just check first?:

                Code:
                if ({image2} == '') {
                    $mail_attachment = '';
                } else {
                    $mail_attachment = '../../_lib/file/img.{id}.'/'.{image2};
                }

                Also - I don't think there should be a leading "/", i.e. '../../_lib/file/img.{id}.'/'.{image2} - NOT '/../../_lib/file/img.{id}.'/'.{image2}

                and if i put it in an array
                $mail_attachment = array ( '/../../_lib/file/img.{id}.'/'.{image2};

                );

                this is wrong as well, there should not be a ; after the image, only after the array closing tag... and if removed, there is more than a single quote in the attachment line, how the php will know that this array line is over? so it will give error as well
                You are correct, there should be no ";" but an array element is separated out with a comma, and I think you need a key also.

                Code:
                $mail_attachment = array(
                    1 =>  '/../../_lib/file/img.{id}.'/'.{image2},
                );
                Though from PHP 5.4 I think you use square brackets:

                Code:
                // as of PHP 5.4
                $array = [
                    "foo" => "bar",
                    "bar" => "foo",
                ];
                But not sure why you are trying with an array? Is $mail_attachment expecting an array?

                Comment


                • #9
                  array is in the code examples of SC, and it was the only way to ignore the field if was empty loooooool ok try to "check first" im not good at that, you gave me good help here lool will try it out

                  here is breaking news about this story, now i put the complete path like:

                  /home/LinuxUser/public_html/domain/project/_lib/file/img'.{id}.'/'. {image2};

                  guess what happened? email was sent normally and quickly, but i got the attachment like 0 bite a file says img111 in my inbox can't be opened! i think this a step forward, almost there..

                  i'm keep trying

                  Comment


                  • #10
                    lol keep on plugging.... :-)

                    I guess it's an array to support multiple attachments, thinking about it.

                    Comment


                    • #11
                      Did you tried using session object to get files path?
                      /Giuseppe

                      Professional Scriptcase Services
                      Some Customers opinions

                      Comment


                      • #12
                        finally could solve this with big help of EricB and adz as well

                        here is a conclusion:

                        the field file is not being reflected in the button sending code, {image2} is returning empty for unknown reason, so we have added global variable in OnLoad event like [glo]={image2} and hence the file name came correctly, finally the path obviously should be the internal and the long one:

                        $attach = '/home/LinuxUser/public_html/domain/project/_lib/file/img'.{id}.'/'.[glo]'

                        Big thanks Eric, big thanks Adz

                        cheers guys ROFL

                        Comment


                        • #13
                          :-) good news

                          Comment

                          Working...
                          X