Announcement

Collapse
No announcement yet.

Email Attachments

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

  • Email Attachments

    Good morning,

    I've spent days and days trying to get this to work, and have searched the threads trying this and that and I'm still missing something here. I'm trying to get a form built, that when completed and submitted, sends two emails - one to one group of folk, and another email to another group. Main reason for this is because one group is not allowed to see part of the data being submitted. On both emails however, I need to include the picture that the person filling out the form has attached.

    I read that it's better practice to add to the database, a link to the image verse having the image saved in the database....and I've tried both ways for the email attachment to be included but failed on them all. I'm deploying to HostGator if that makes any difference and the emails go out fine to the groups they need to go to, but the image is never there... I've even included a hard link in the email to an image I know is there (I can open up the link in my browser and see the image) but the attachment is still not successful.

    Here is my code edited a bit for privacy so hopefully I didn't mess that up - all on event "OnAfterInsert":

    ===============================
    [rptid] = {Rcrdid};
    $mail_message = NULL;

    // Get details of new submission
    $check_sql = "SELECT added, name, image FROM reports WHERE rcrdid = [rptid]";
    sc_lookup(rp, $check_sql);
    [rp_added] = {rp[0][0]};
    [rp_name] = {rp[0][1]};
    [image] = {rp[0][3]};


    // Get email settings for sending mail
    sc_lookup(em, "SELECT smtp_server, smtp_user, mail_from, smtp_pwd, mail_to_attorney, mail_to_board FROM mail_settings WHERE type = 'main'");
    [server] = {em[0][0]};
    [user] = {em[0][1]};
    [from] = {em[0][2]};
    [pwd] = {em[0][3]};
    [sendto] = {em[0][4]};

    // Set image path - directory
    [fp] = "../_lib/file/img/";

    // ** Send email notification
    // Email parameters
    $mail_smtp_server = "[server]"; // SMTP server name or IP address
    $mail_smtp_user = "[user]"; // SMTP user name
    $mail_smtp_pass = "[pwd]"; // SMTP password
    $mail_from = "[from]"; // From email
    $mail_to = "[sendto]"; // To email
    $mail_subject = "New Submission: " . [rptid]; // Message subject
    $mail_message = $mail_message.'The following information was just submitted from the site: <br><br>'; // Message body
    $mail_message = $mail_message.'Reported date: ' . date("l, jS \of F Y",strtotime([rp_added])) . '<br>';
    $mail_message = $mail_message."Individual reporting: " . [rp_name] . "<br>" ;
    $mail_message = $mail_message.'Thank you. ' . '<br>';
    $mail_format = 'H'; // Message format: (T)ext or (H)tml
    $mail_attachments = '[fp].[image]';

    // Send email";
    sc_mail_send($mail_smtp_server,
    $mail_smtp_user,
    $mail_smtp_pass,
    $mail_from,
    $mail_to,
    $mail_subject,
    $mail_message,
    $mail_format,
    '',
    '',
    '',
    $mail_attachments);
    ========================================

    Then I clear it the message out with
    $mail_message = NULL;
    Before doing a similar action for the second email.

    I've tried so many different variations that I've lost track of them all, but I must be missing something somewhere and hopefully it's an easy catch for someone else?

    Thanks very much for any help you're able to provide.

    Mark.

  • #2
    Hey Mark:

    My Recomendation... do an echo of all your variables to screen, tbh with you this I dont like and i think is the main problem you have.

    PHP Code:
    $mail_attachments '[fp].[image]'; <--- this works only with double quotes ""

    //this should
    $mail_attachments = [fp] . [image]; 
    That line bugs me... try echoing the variables to see if they are being set propperly.

    Regards.

    Comment


    • #3
      Hey Mark:

      My Recomendation... do an echo of all your variables to screen, tbh with you this I dont like and i think is the main problem you have.

      PHP Code:
      $mail_attachments '[fp].[image]'; <--- this works only with double quotes ""

      //this should
      $mail_attachments = [fp] . [image]; 
      That line bugs me... try echoing the variables to see if they are being set propperly.

      Regards.

      Comment


      • #4
        Hey kafecadm,

        Thanks SO much for your feedback. It at least tells me I'm on the right track. Unfortunately I still can't get it to work - I created a control for the form to jump to after submitting the picture, and it's echoing the path I'm trying to use - but no picture attachment. I've tried so many different variations but can't get it to go through...for example:

        ../reports/_lib/file/img/
        ../_lib/file/img/
        /_lib/file/img/

        and when I echo it, I'm getting what my path I'm trying is - for example on the middle one, my control echoes:
        ../_lib/file/img/1.png

        and on all my tests, no image is attached to the email. I've confirmed the images are being saved to _lib/file/img/ - I can see them. And as I mentioned in my first post, I can put a hard link into the form to pull the web link I can copy/paste, and the image is still not being included. I'm going to keep banging away and either my fatigue or my sanity will finally give in =)

        Thanks though - I know I'm at least close....

        Comment


        • #5
          I put the whole web address as the [fb] and ran it. Then copy/pasted the echo right into my browser and it pulls up the image - but still no attachment. It's almost like there's a setting that's not allowing the image to be added to the email.... aargh.

          Comment


          • #6
            oh man that explains it... try not to use relative paths.." ../folder/otherfolder/" use absolute paths "myuser/home/scriptcase/someFolder/img/1.png", this is common working with files. try that and lets c how it goes.

            Regards

            Comment


            • #7
              Hey kafecadm,

              Thanks again for your assistance on this. Didn't want you to think I wasn't working on it so quick update. I started with the farthest out link:

              /public_html/reports/_lib/file/img

              and am now copy / pasting the path I use into the form so I have it in the email for tracking's sake =)

              That didn't work,

              So I tried with out the first '/'

              public_html/reports/_lib/file/img

              That didn't work so I took out public_html..... and so on. I'm going to remove one item at a time until theoretically the image will come through....I hope. Problem now is hostgator is not sending the email right away, so I'm having to wait 30 - 60 minutes between attempts.

              I'll definitely let you know how it turns out - what works e.t.c.

              Thanks again for your help on this. It's truly very much appreciated! I'm doing it for free for a non-profit, and have spent around 12 hours on this little piece alone. The rest of the form was super easy! LOL

              Cheers.

              Comment


              • #8
                Well lemme know if I can be of any assistance.

                Regards

                Comment


                • #9
                  Hi kafecadm,

                  I'm at a loss - I've now spent weeks on this and must be missing the boat somewhere. Maybe it's the database field type (blob)? If I create a form to review the records I've added, I can see the images - so I'm assuming the upload and field type are working fine....but none of my paths worked and I've sent literally hundreds of emails trying different things.

                  Tested with image directly in path

                  ../../_lib/file/img/1.png
                  _lib/file/img/1.png

                  or as variable at the end of these paths:

                  /
                  img/
                  /img/
                  file/img/
                  /file/img/
                  _lib/file/img/
                  /_lib/file/img/
                  reports/_lib/file/img/
                  /reports/_lib/file/img/
                  public_html/reports/_lib/file/img/
                  /public_html/reports/_lib/file/img/
                  user/public_html/reports/_lib/file/img/

                  When editing a file, I noticed my user name wasn't the listed root path, so I tried:

                  /user/public_html/reports/_lib/file/img/
                  /home3/user/public_html/reports/_lib/file/img/

                  Or not doing direct links:

                  ../../../_lib/file/img/
                  ../../_lib/file/img/
                  ../_lib/file/img/
                  _lib/file/img/

                  To the seasoned hand, I'm sure this looks ludicrous, but I was desperately trying to find a path that would successfully pull the image.

                  I'm querying the record, and assigning [image] to the returned field from my query. Then in the email, using the [image] variable at the end of the path - but I get nothing. I've even changed the form to just write the image to the database (I know this is bad design but I just wanted to see it work) and even with it in the database (so no path is needed I assume) I still don't get an attachment - so it must be something else I'm doing wrong.

                  I hate to keep this thread alive for nothing..... If I can't get it working, the users will just have to log in and review the records in a form - instead of getting it in their email =)

                  Thanks in advance for any ideas / tricks I could try to see how to get it to work

                  Comment


                  • #10
                    Ok man, lets review everything again ok?... you are trying to include it into an email right?... if you have the image into a blob... then you need to place it out of the database before you attach it. ar you doing this?. could you please share your entire code with us?.

                    Regards

                    Comment


                    • #11
                      hi guys, hi kafe sempai

                      sorry to interrupt, kafe is the boss, i just want to share my experience with this specific stupid issue, i spent long days working on it last year

                      well, blob will work, finally, but i kept it as plan b (later proofed it can work) but for the best practice, and to keep the images away from a heavy database, I would recommend to have it as image (filename)

                      now your point will all be in the path

                      this attachment code worked with me, and sends the image as attached file normally, just add your normal code of sc send mail and use the attachment variable this way.. it is tested, however, important point you need to look if you are using "sub folder" for the image when storing, then you need to add that too if used,

                      another issue was facing, that sometimes there is attachment and sometimes no attachment... so chose to do it this way

                      Code:
                      [imgvar] = {imagefieldname};
                      if (empty([imgvar]))
                      	{
                      $mail_attachments = ' ';
                      	}
                      else {
                      $mail_attachments = '/home/serveruser/public_html/hostuser/project/_lib/file/img'.{recid}.'/'.[imgvar];
                      }
                      // then add $mail_attachments in the array, this way
                      
                      sc_mail_send($mail_smtp_server,
                      			 $mail_smtp_user,
                      			 $mail_smtp_pass,
                      			 $mail_from,
                      			 $mail_to,
                      			 $mail_subject,
                      			 $mail_message,
                      			 $mail_format,
                      			 '',
                      			 '',
                      			 '',
                      			 '',
                      			 $mail_attachments);
                      I know you would say that could use directly {imagefieldname} in the path... that was the issue, didn't work unless made it this way, was using SC v7.1 and now on 8 not sure if it will work using the direct image field, u can try both and c

                      let us know what happens with you

                      cheers
                      Last edited by MikeDE; 07-28-2015, 04:37 PM.

                      Comment


                      • #12
                        Always wellcome to join us MIKEDESAMACHANSEMPAI... :P.

                        Comment


                        • #13
                          Originally posted by kafecadm View Post
                          Always wellcome to join us MIKEDESAMACHANSEMPAI... :P.
                          Hey, why I wasn't invited to the party? I would like to have a pseudonym too. Lol
                          /Giuseppe

                          Professional Scriptcase Services
                          Some Customers opinions

                          Comment


                          • #14
                            Originally posted by Giu View Post
                            Hey, why I wasn't invited to the party? I would like to have a pseudonym too. Lol
                            welcome giu, you already have one dear, 3 letters similar to GUI

                            that long name there you need to see here it is nice

                            kafe started it few months ago and he became the sempai actually he is genius and very helpful... one of the premium life savers here in the forums

                            cheers guys

                            Comment


                            • #15
                              From now on you shall be known as SC Graphic User Interface... oh dang ... not so clever uh?... lol >.<

                              Comment

                              Working...
                              X