简体   繁体   English

如何将表单数据从sencha发送到php电子邮件脚本

[英]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. 我正在尝试使用sencha touch表单功能将表单内容发送到PHP邮件脚本。 I have pretty weak knowledge in php and sencha but still trying to make it work with a php example script I found. 我在php和sencha方面的知识很薄弱,但是仍然尝试使其与我发现的php示例脚本一起使用。 The sencha part is basic feedback form with 3 fields. sencha部分是具有3个字段的基本反馈形式。

Here is the sencha part of the code: 这是代码的sencha部分:

       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(); this.up('formpanel')。submit(); line is in charge of sending the data to the feedback.php script which looks like this: 行负责将数据发送到feedback.php脚本,如下所示:

<?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) 上面的方法可以正常工作并发送电子邮件,但只能通过以下方式使用'label:'The Bad'的最后字段内容:null:ff(当为最后一个字段输入ff时)

It looks to me that the PHP loop of assembling the message is the problem but perhaps I am not transferring the data correctly? 在我看来,组装消息的PHP循环是问题所在,但也许我没有正确传输数据?

Any suggestions? 有什么建议么? Thanks in advance. 提前致谢。

Hmm your fields in the Sencha example don't have names. 嗯,您在Sencha示例中的字段没有名称。 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. 我将使用Fiddler2截取正在发送的数据,并查看POST中是否包含您期望的实际数据。 Maybe try just giving them all names for the fields and just reference them directly? 也许尝试仅给它们提供字段的所有名称,然后直接引用它们?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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