1 2 Previous Next 21 Replies Latest reply on Nov 22, 2011 10:08 AM by KAmsinger

    Triggering an email script through php

    shryn_1

      Title

      Triggering an email script through php

      Your post

      Hi,

       

      I have goolgled high and low for an answer to my problem.

       

      I am setting up a request form database for my client with a php interface using the instant web publishing tools. My database is configured to send email through smtp and it works well when sending from the database with a single record, but keeps on sending from an incorrect record when there is more than one record in the database. I came across a comment, while googling, that this is a known bug.

       

      Is this true/is there a workaround?

       

      Any help would be appreciated.

       

      shryn

       

      New to PHP IWP

      Filemaker Server 10

      OS X Server

        • 1. Re: Triggering an email script through php
          TSGal

          shryn:

           

          Thank you for your post.

           

          Make sure your Send Mail script uses "One mail using data from the current record" rather than "Multiple emails".  As long as you have a button on the Layout to execute that script, it should send the information from the current record.  Remember that Instant Web Publishing is using a browser to display the data from a FileMaker Pro database file, so if you are in List view, the last record displayed, depending on the browser, could be the current record.

           

          TSGal

          FileMaker, Inc.

          • 2. Re: Triggering an email script through php
            shryn_1

            Hi TSGal,

             

            Sorry. I made a mistake. I'm asking about Custom Web Publishing with PHP, not Instant Web Publishing.

             

            I am using the PHP Site Assistant tool to create the web interface and an email from an incorrect record is sent when the Save Record button is clicked.

             

            I have   $newPerformScript =& $fm->newPerformScriptCommand('RequestForm', 'TechEmail'); $result = $newPerformScript->execute();

             

            script command and I have made sure "One mail using data from the current record" is set.

             

            Sorry for the confusion.

             

            shryn

             

             

            • 3. Re: Triggering an email script through php
              TSGal

              shryn:

               

              Thank you for the additional information.

               

              Nothing is coming immediately to mind.  However, it is obvious that the script is accessing a record other than the one you were expecting.  Can you tell me anything about the "incorrect" record?  Does it precede the current record?  Is it the first or last record in the table?  Is it the first or last record sorted?  What other steps do you have just prior to the $newPerformScript->execute() command?

               

              TSGal

              FileMaker, Inc.

              • 4. Re: Triggering an email script through php
                shryn_1

                I would say the records sent are pretty random. Sometimes it is the first record, often it's another, but never the current record. The records aren't sorted and they are very simple, with 12 fields and no calculations, other than 2 pull-down value lists. The PHP code is completely generated by the PHP Site Assistant, except for the script trigger above. I'll attach the PHP code, if needed.

                 

                Many thanks,

                 

                shryn

                 

                 

                 

                • 5. Re: Triggering an email script through php
                  TSGal

                  shryn:

                   

                  Yes, attach the PHP code.  This may help provide a clue.

                   

                  TSGal

                  FileMaker, Inc.

                  • 6. Re: Triggering an email script through php
                    shryn_1

                    OK here is the code from the confirmation.php page...

                     

                    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
                    <?php
                    
                        /**
                        * FileMaker PHP Site Assistant Generated File
                        */
                    
                        require_once 'fmview.php';
                        require_once 'FileMaker.php';
                        require_once 'error.php';
                    
                        $cgi = new CGI();
                        $cgi->storeFile();
                        
                        $databaseName = 'TechRequests';
                        $layoutName = 'RequestFormOutput';
                    
                        $userName = $cgi->get('userName');
                        $passWord = $cgi->get('passWord');
                    
                        $fm = & new FileMaker();
                        $fm->setProperty('database', $databaseName);
                        $fm->setProperty('username', $userName);
                        $fm->setProperty('password', $passWord);
                        
                        ExitOnError($fm);
                        $layout = $fm->getLayout($layoutName);
                        ExitOnError($layout);
                    
                        // formats for dates and times
                        $displayDateFormat = '%m/%d/%Y';
                        $displayTimeFormat = '%I:%M:%S %P';
                        $displayDateTimeFormat = '%m/%d/%Y %I:%M:%S %P';
                        $submitDateOrder = 'mdy';
                    
                        // create the new add command
                        $newrecordrequest = $fm->newAddCommand($layoutName);
                        ExitOnError($newrecordrequest);
                    
                        // get the submitted record data
                        $recorddata = $cgi->get('recorddata');
                        if (isset ($recorddata)) {
                    
                            //  submit the data to the db
                            $result = submitRecordData($recorddata, $newrecordrequest, $cgi, $layout->listFields());
                    
                    
                    // Run script
                        
                        $newPerformScript =& $fm->newPerformScriptCommand('RequestForm', 'TechEmail'); $result = $newPerformScript->execute();
                    
                            //  clear the stored record data
                            $cgi->clear('recorddata');
                            ExitOnError($result);
                            if ($result->getFetchCount() > 0) {
                                $records = $result->getRecords();
                                $record = $records[0];
                            }
                        }
                        ExitOnError($record);
                    ?>
                    <html>
                        <head>
                            <meta http-equiv="content-type" content="text/html; charset=utf-8">
                            <link rel="stylesheet" type="text/css" media="screen" href="agentis.css">
                            <title>
                                Confirmation
                            </title>
                        </head>
                        <body>
                            <div id="header">
                                <!-- HEADER -->
                                <div id="headerlogo">
                                    TechRequests 
                                    <div id="headercaption">
                                        <!--Caption for the Company-->
                                    </div>
                                </div>
                            </div>
                            <div id="content">
                                <!--Navigation Menu-->
                                <?php include_once 'navigation.php' ?>
                                <table cellpadding="0" cellspacing="0" class="contentbg">
                                    <tr>
                                        <td class="contentbgleft">
                                        </td>
                                        <td class="contentmidrecords">
                                            <div id="contenttitlebg">
                                                <!-- PAGE BODY -->
                                                <h1>
                                                    Confirmation
                                                </h1>
                                            </div>
                                            <table class="message" cellpadding="2" cellspacing="2">
                                                <tr>
                                                    <td class="messagedisplay">
                                                    </td>
                                                </tr>
                                            </table>
                                            <table class="curvedbg">
                                                <tr>
                                                    <td>
                                                    </td>
                                                </tr>
                                            </table>
                                            <div class="scrolladd">
                                                <table cellpadding="1" cellspacing="0" class="recwidth">
                                                    <tr>
                                                        <td valign="top">
                                                            <table cellpadding="1" cellspacing="6" class="record">
                                                                <!-- Display record field values -->
                                                                <tr class="field">
                                                                    <td class="field_name">
                                                                        FL_Name
                                                                    </td>
                                                                    <td class="field_data">
                                                                        <?php echo nl2br(storeFieldNames('FL_Name', 0, $record, true, 'EDITTEXT', 'text'))?>
                                                                    </td>
                                                                </tr>
                                                                <tr class="field">
                                                                    <td class="field_name">
                                                                        Request Type
                                                                    </td>
                                                                    <td class="field_data">
                                                                        <?php echo nl2br(storeFieldNames('Request Type', 0, $record, true, 'EDITTEXT', 'text'))?>
                                                                    </td>
                                                                </tr>
                                                                <tr class="field">
                                                                    <td class="field_name">
                                                                        EQ
                                                                    </td>
                                                                    <td class="field_data">
                                                                        <?php echo nl2br(storeFieldNames('EQ', 0, $record, true, 'EDITTEXT', 'text'))?>
                                                                    </td>
                                                                </tr>
                                                                <tr class="field">
                                                                    <td class="field_name">
                                                                        Request Data
                                                                    </td>
                                                                    <td class="field_data">
                                                                        <?php echo nl2br(storeFieldNames('Request Data', 0, $record, true, 'EDITTEXT', 'text'))?>
                                                                    </td>
                                                                </tr>
                                                                <tr class="field">
                                                                    <td class="field_name">
                                                                        Email
                                                                    </td>
                                                                    <td class="field_data">
                                                                        <?php echo nl2br(storeFieldNames('Email', 0, $record, true, 'EDITTEXT', 'text'))?>
                                                                    </td>
                                                                </tr>
                                                                <tr class="field">
                                                                    <td class="field_name">
                                                                        Room Number
                                                                    </td>
                                                                    <td class="field_data">
                                                                        <?php echo nl2br(storeFieldNames('Room Number', 0, $record, true, 'EDITTEXT', 'text'))?>
                                                                    </td>
                                                                </tr>
                                                                <tr class="field">
                                                                    <td class="field_name">
                                                                        ExtNum
                                                                    </td>
                                                                    <td class="field_data">
                                                                        <?php echo nl2br(storeFieldNames('ExtNum', 0, $record, true, 'EDITTEXT', 'text'))?>
                                                                    </td>
                                                                </tr>
                                                                <tr class="field">
                                                                    <td class="field_name">
                                                                        WebEmail Sent
                                                                    </td>
                                                                    <td class="field_data">
                                                                        <?php echo nl2br(storeFieldNames('WebEmail Sent', 0, $record, true, 'EDITTEXT', 'text'))?>
                                                                    </td>
                                                                </tr>
                                                                <tr class="field">
                                                                    <td class="field_name">
                                                                        NewStatus
                                                                    </td>
                                                                    <td class="field_data">
                                                                        <?php echo nl2br(storeFieldNames('NewStatus', 0, $record, true, 'EDITTEXT', 'number'))?>
                                                                    </td>
                                                                </tr>
                                                                <tr class="field">
                                                                    <td class="field_name">
                                                                        Request Number
                                                                    </td>
                                                                    <td class="field_data">
                                                                        <?php echo nl2br(storeFieldNames('Request Number', 0, $record, true, 'EDITTEXT', 'text'))?>
                                                                    </td>
                                                                </tr>
                                                                <tr class="field">
                                                                    <td class="field_name">
                                                                        Date Created
                                                                    </td>
                                                                    <td class="field_data">
                                                                        <?php echo displayTimeStamp(storeFieldNames('Date Created', 0, $record, true, 'EDITTEXT', 'timestamp'), $displayDateTimeFormat)?>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </td>
                                        <td class="contentbgright">
                                             
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="contentbgfooterleft">
                                             
                                        </td>
                                        <td class="contentfooter">
                                             
                                        </td>
                                        <td class="contentbgfotterright">
                                             
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <!-- Footer-->
                            <table class="footerwidth" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td>
                                        <?php include_once 'footer.php' ?>
                                    </td>
                                </tr>
                            </table>
                        </body>
                    </html>
                    
                    

                     

                     

                    • 7. Re: Triggering an email script through php
                      thomas1_1

                      Hello,

                      i have the same problem, the script is running on another random record, but not on the last submited record (in the same php session and on the same layout).

                      have you found something new ?

                      Thank for your help.

                       

                      • 8. Re: Triggering an email script through php
                        shryn_1

                        Hi TSGal,

                         

                        Has any solution to my problem come to mind?

                         

                        Best regards,

                         

                        shryn

                        • 9. Re: Triggering an email script through php
                          TSGal

                          shryn:

                           

                          Our Testing department would like to see your database file and PHP generated files.  I have sent you a private message (top of this page - right side - envelope icon just below the blue horizontal bar) with instructions where to send the files.

                           

                          TSGal

                          FileMaker, Inc.

                          • 10. Re: Triggering an email script through php
                            Kobyashi

                            It's a long shot to say the least but, whenever I find things like this happening it's when I am using a table view and have specified the wrong source table somewhere, perhaps in the actual data listing on a layout or as the layout source. E.G. If you have a table called contacts and a view of contacts 1 and a record serial field called ID, rerencing the contacts::ID when you mean to reference contacts 1::ID can produce this issue.

                             

                            As i said, it's just a long shot.

                            • 11. Re: Triggering an email script through php
                              shryn_1

                              Thanks for the suggestion. Unfortunately, I have tested the issue with a very simple database consisting of a single table with a couple of fields and a trigger script. The result is the same. The script triggers the email, but the record sent is not the currently generated one.

                               

                              Ah well! I'll keep on plugging away...

                              • 12. Re: Triggering an email script through php
                                shryn_1

                                Hi TSGal,

                                 

                                Is there an update on my inquiry?

                                 

                                Best regards,

                                 

                                shryn

                                 

                                • 13. Re: Triggering an email script through php
                                  shryn_1

                                  It would be nice get an answer one way or another regarding my issue. Is it solvable or not?

                                   

                                  -shryn

                                  • 14. Re: Triggering an email script through php
                                    littledog

                                    Hi, take a look HERE or HERE

                                    Script triggering via PHP and script is as you want.

                                    1 2 Previous Next