简体   繁体   中英

How to send form data from sencha to php email script

I am trying to use sencha touch form functionality to send the form content to PHP mail script. I have pretty weak knowledge in php and sencha but still trying to make it work with a php example script I found. The sencha part is basic feedback form with 3 fields.

Here is the sencha part of the code:

       feedbackForm = Ext.create("Ext.tab.Panel", {
            items: [{
                title: 'Feedback',
                iconCls: 'user',
                xtype: 'formpanel',
        url: 'feedback.php',                    
                layout: 'vbox',
                tabBar: false,
                items: [
                                {
                                    xtype: 'fieldset',
                                    tabBar: false,
                                    items: [
                                        {
                                            xtype: 'textfield',
                                            label: 'Your Name'
                                        },
                                        {
                                            xtype: 'emailfield',
                                            label: 'Your Email'
                                        },
                                        {
                                            xtype: 'textfield',
                                            label: 'The Good'
                                        },
                                        {
                                            xtype: 'textfield',
                                            label: 'The Bad'
                                        }
                                    ]
                                },
                                {
                                    xtype: 'button',
                                    text: 'Send',
                                    ui: 'confirm',
                                    handler: function() {
                                        this.up('formpanel').submit();                                          
                                    }
                }]
                }]
            });

The this.up('formpanel').submit(); line is in charge of sending the data to the feedback.php script which looks like this:

<?php
// Configuration Settings
$SendFrom =    "Form Feedback <feedback@myDomain.com>";
$SendTo =      "myEmail@gmail.com";
$SubjectLine = "Feedback Submission";
$ThanksURL =   "thanks.html";  //confirmation page

// Build Message Body from Web Form Input
foreach ($_POST as $Field=>$Value)
 $MsgBody .= "$Field: $Value\n";
sgBody .= "\n" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n" .
 $_SERVER["HTTP_USER_AGENT"];
sgBody = htmlspecialchars($MsgBody, ENT_NOQUOTES);  //make safe

// Send E-Mail and Direct Browser to Confirmation Page
mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom");
header("Location: $ThanksURL");
?>

The above is working and sending an email but only with the last field content of 'label: 'The Bad'' in the following way: null: ff (when entered ff for the last field)

It looks to me that the PHP loop of assembling the message is the problem but perhaps I am not transferring the data correctly?

Any suggestions? Thanks in advance.

Hmm your fields in the Sencha example don't have names. Are they overwriting each other? If you comment out the 'The Bad' field is the one that comes up the 'The Good' field? I guess it could be just sending over a collection of items. I'd use Fiddler2 to intercept the data being sent and see if the POST has the actual data in it that you are expecting. Maybe try just giving them all names for the fields and just reference them directly?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM