电子邮件对自己用户提交的表单 - 混合应用程序 [英] mail to myself a user's submitted form - hybrid app

查看:274
本文介绍了电子邮件对自己用户提交的表单 - 混合应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个混合的应用程序,我使用jQuery Mobile的。该应用程序应该是在移动,而不是一个web应用程序安装。我试着做一些研究,但仍无法理解如何来完成我想要的。

I am trying to build a hybrid app, I am using jquery mobile. The app is supposed to be installed on the mobile and not a web-app. I tried doing some research but still couldn't understand how to accomplish what I want.

我要插入一个表格,供用户填写(如:电子邮件,姓名,电话,文本),我想,当提交的字段将被邮寄给自己。 据我所知,这是不可能插入到PHP jQuery Mobile的,因为它不支持它,或者类似的东西。但是,我看到了,它可能通过AJAX调用PHP脚本。但我不明白它是如何做的,因为PHP是服务器端它在某处被托管的吧?

I want to insert a form for the user to fill (such as: mail, name, telephone, text) and I want that when submitted the fields will be mailed to myself. I understand that it isn't possible to insert php to jquery mobile because it doesn't support it or something like that. However, I saw that it's possible to call a php script through AJAX. But I don't get how it's done because PHP is server side it has to be hosted somewhere right?

所以我需要在网络上举办一个php文件,并通过应用程序通过它的URL调用它呢? 我发现,确实我想正是一个PHP脚本,但我不明白,如果它是可用通过混合应用程序。

So I need to host on the web a php file and call it through the app by it's URL? I have found a php script that does exactly what I want but I don't understand if it's useable through hybrid app.

我也读了JavaScript不能邮寄的东西直接到我的电子邮件地址,它只有在邮寄地址功能,打开电子邮件的形式。

I also read that javascript can't mail something straight to my email address, it only has the mailto function which opens a mail form.

我无法找到一个答案,而我真的AP preciate,如果有人可以给我解释一下它是如何工作的,如果它甚至有可能。

I couldn't find an answer to that, and I would really appreciate if someone could explain to me how it works and if it's even possible.

推荐答案

它很容易,但对于初学者它可能是一个艰巨的任务设置,使病人写大量的说明和安装任务,让你开始。

Its very easy, but for a beginner it may be a daunting task to set up so ill write Plenty of Notes and Installation tasks to get you started.

prerequisites的主页设置PHP和电子邮件功能。对于远程主机设置我想一切都为您安装,但可能需要一定的成本,因此对于家庭使用,自己这样做的好处是,它的自由。

Prerequisites for a Home Setup with PHP and EMAIL Capabilities. For Remote Hosting Setup I guess everything is Installed for you but may require some Cost, so for Home use and doing it by yourself the bonus is that its Free.

1)备用计算机至少1GIG RAM和硬盘10gigs。如果你没有备用的一个或不能买得起,在他的时刻,你可能能够使用类似虚拟箱是免费的您当前的计算机之上虚拟化之一。如果你想100%的现场服务的计算机必须在所有的时间和连接到互联网。

1) A Spare Computer with at least 1gig of ram and 10gigs of hard disk. if you don't have a spare one or cant afford one at he moment you may be able to Virtualize one on top of your current computer using something like Virtual box which is free. If you want 100% live service the computer must be on all the time and connected to the Internet.

2)的服务器操作系统preferably Linux的一个。在这个例子中会使用Ubuntu的服务器。为什么?因为它很容易设置和安装额外的工具,框架和方案,易于管理,并拥有所有你永远都需要的功能和其快速。

2) A Server OS preferably Linux one. In this example will use UBUNTU Server. Why? Because its Very easy to setup and install extra utilities, frameworks and programs, easy to manage and has all the features you will ever need and its Fast.

3)邮件帐户。 GMAIL作为发送邮件的例子。

3) A Mail Account. GMAIL as an example for sending emails.

4)的Internet连接。

5)网络电缆将计算机连接到路由器。即使您选择无线的网络电缆来连接你可能需要下载额外的驱动程序,让您的无线网卡工作,并连接最有可能的,你首先需要一个网络线。明智的做法是不要使用无线对于这样的设置对于一些原因,如安全性,连接丢失(弱信号)等

5) A network Cable to connect the computer to your Router. Even if you choose Wireless over a Network Cable to connect you may need to download additional drivers to get your Wireless card Working and Connecting Most likely you will need a Net Cable first. It is advisable not to use Wireless for Such Setup for a number of Reasons such as Security, Loss of Connection (Weak Signal) etc

就是这样。总的安装时间约35分钟。 10分钟进行设置的休息25分钟用于安装操作系统,所以你可以通过PHP发送电子邮件。

That's it. Total Installation time About 35 minutes. 25 mins for installing the OS and 10 mins for the rest of setup so you can send emails Via PHP.

在安装

1)安装Ubuntu服务器访问的Ubuntu下载最新版本。

1) Install UBUNTU Server Visit Ubuntu to Download the Latest Version.

服务器而不是桌面版中除服务器版本的有点慢。然而,缺点使用服务器版本是,你需要通过命令行来学习如何编辑一些基本的命令,复制,移动,删除,围绕服务器文件的更改权限。但它不是火箭科学。

Server not the Desktop Version as its a bit slower than the Server version. However the downside to using the Server version is that you need to learn some basic commands on how to edit, copy, move, delete, change permissions of files around the server via command line. But its not rocket science.

在好的一面托管在Linux服务器,该服务器可容纳100的脚本,CSS和网页文件的网站,你可以做的是安装Samba服务器,它使您能够共享您的Web文件夹(S)或文件夹这个问题在你的本地网络或从外部所以使用另一台PC上可以说,Windows可以连接到该文件夹​​,使您能够在Windows上进行编辑使用所有您最喜爱的软件,并保存你的Linux服务器哪一个更容易对这些文件,而不是使用直接在服务器上编辑工具。大约需要一分钟安装和设置Samba服务器。我将添加到该指南的底部。

On the good side hosting websites on Linux Server which may hold 100's of files of scripts, CSS, and Web pages, what you can do is install SAMBA server which enables you to share your web folder(s) or any folder for that matter over your Local Network or from Outside so on another PC using Lets say Windows can connect to that folder and will enable you to use all your favorite software on windows for editing and Saving those files on your Linux Server which is easier rather than using editing utilities directly on the server. takes about a minute to install and setup a Samba server. I will add that to the bottom of this Guide.

一旦这样做了

2)安装LAMP服务器

这将安装

Apache网络服务器,MySQL数据库和PHP

Apache Web Server, Mysql Database, and PHP

pretty的多少,所有你需要开始托管网站(阿帕奇),具有数据库(MySQL的)的Web应用和服务器端语言来处理所有的工作(PHP)。

Pretty much all you need to start hosting websites (Apache), have databases (Mysql) for web uses and a server side language to handle all the work (PHP).

命令

(须藤需要在Ubuntu的命令的前面,因此您可以在管理模式,这是更安全的运行。它会问你为你的帐号密码,运行命令的其余部分之前)

(sudo is required in ubuntu in front of commands so you can run them in admin mode which is more Secure. It will ask you for your account password, before running the rest of the command)

让运行它,它会自动下载所需的文件,所以请确保您连接到互联网。你会被要求的唯一的问题是MySQL数据库的根访问输入密码。

Let it run, It will Auto download the required files so make sure you are connected to the internet. The only question you will be asked is type in a password for the root access of Mysql database.

Apache,MySQL和PHP还可以被配置所以未来的一些基本的学习曲线。

Apache, Mysql, PHP can be further configured so there is some basic learning curve for the future.

我从来没有配置MySQL,Apache配置我通常会改变的路径在我的网站和一些安全设置。默认的目录,你的网站相关的文件进入是(在/ var / www / html等)。这html目录是所有的PHP,HTML文件进入。然而,没有任何理由,为什么你不能重命名此文件夹,重新配置Apache直接使用它作为你的根Web文件夹。生病解释如何做到这一点接近本指南的结尾。对于PHP配置,您可能需要在某些时候安装额外的扩展,如的php5-imagick 这是使用PHP编辑图像库。还有许多扩展,可以使PHP做很多事情。

I never had to configure Mysql, for Apache configuration i usually change the Path to where my website is and some Security settings. The default directory where your web related files go into is (/var/www/html). This html directory is where all the PHP, HTML files go into. However, there's no Reason why you cant rename this folder and reconfigure apache to directly use it as your root web folder. Ill explain how to do this near the end of this guide. For PHP configuration, you may need at some point to install extra extensions such as php5-imagick which is a library for editing images using PHP. There are many extensions that can enable PHP to do many things.

中途有

电子邮件设置

命令

片刻之后,将present你一些选项在设置邮件。

After a few moments it will Present You with Some Options In setting Up Mail.

您想要的(互联网站点),我认为它的第三个选项下。选择此

You want (Internet Site) i think its the 3rd option Down. Choose this

您再看看您的主机名。不需要采取任何行动在这里,继续

You will then see your hostname. No action Required here, Continue

这是邮件完成,但我们需要配置一些位,以便它知道邮件配置

That's the Mail Done, but we need to configure some bits to it so it knows about the mail configuration

打开后缀的配置文件

命令

在文件中添加以下内容,你可以把它添加的文件的末尾

add the following in the file, you can put it add the end of the file

relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

您可能会看到(中继主机= )已经在文件中。你可以做的就是删除该行并添加上述所有在那里。

you may see (relayhost =) already in the file. what you can do is delete that line and add all the above there.

纳米是一个文本编辑器,因此可自由使用光标键移动上下,删除,请键入等。当你完成编辑。做 CNTRL X 和preSS (是)编写并退出该文件。如果您在文件preSS犯了一个错误的 N (否)只是退出而不写入文件。

nano is a text editor, so freely move with the cursor keys up down, delete, type etc. When you finish editing. do CNTRL X and press Y (Yes) to write and exit the file. If you made a mistake in the file press N (No) to just exit without writing to the file.

几乎没有

修改Postfix的电子邮件帐户信息的文件,并插入(在本例中的Gmail帐户)的日志信息。

edit the Postfix email Account Information file and insert (In our example Gmail account) logging information.

命令

应该是一个空白文件,所以插入

should be a blank file, so insert

[smtp.gmail.com]:587    USERNAME@gmail.com:PASSWORD

变化USERNAME@gmail.com到您的电子邮件帐户和密码的电子邮件密码。它需要这个信息,以便后缀可以连接到Gmail并发送邮件

change USERNAME@gmail.com to your email account and PASSWORD to the emails password. It needs this info so Postfix can connect to Gmail and send mails

我建议创建你的应用程序的名称一个新的新的电子邮件帐户。 my_app_name@gmail.com所以你必须通过你的应用程序发送电子邮件可分辨帐户名称。

I suggest creating a new fresh email account with your App's Name. my_app_name@gmail.com so you have a distinguished account name for sending emails through your app.

CNTRL X 以保存并退出该文件

CNTRL X and Y to save and exit the file

现在,我们解决了一些权限的文件

Now we fix some permissions to the files

修复权限和更新后缀配置使用sasl_passwd文件:

Fix permission and update postfix config to use sasl_passwd file:

指令

接下来,验证证书。你说的是什么呢?只要运行下面的命令,你看到一堆约200人随机字符?如果是这样那是你的服务器证书发送邮件。

Next, validate certificates. You say what??? Just run the following command, Do you see a bunch of Random characters about 200 of them? If so that's your servers Certificate for sending Mails.

(不需要进一步的行动猫命令只列出在屏幕上的文件)命令

command (no further action is required as cat is the command to just list a file on screen)

全部完成现在你可以发送邮件,但是,我们做了一些修改的文件上方,从而让我们先重装后缀采取的变化。

ALL DONE You can send mails now, However we made some changes to the files above so lets reload Postfix first to take in the changes.

命令

做一个测试

命令从服务器发送电子邮件

command to send an email from the server

检查你得到的邮件?

如果是的话那么你可以直接从服务器发送邮件

If yes then you are able to send mails directly from the server

好了,现在你可以从你的web服务器,您需要使用Ajax发表后的表单数据的Java脚本文件到PHP文件在Web服务器上和撰写电子邮件,并将其发送发送电子邮件。

Ok now that you can send emails from your web server you need to use Ajax Post to post the form data in your java script files over to a PHP file on your web server and compose the email and send it.

在你考虑购买一个域名(mywebsitename.com)就可以开始使用你的家用路由器的WAN地址测试。

Before you consider buying a domain name (mywebsitename.com) you can start testing using the WAN address of your home router.

如果您不知道当前的地址打开浏览器,输入(什么是我的广域网地址)

If you don't know the current address open a browser and type (What is my WAN address)

如。

http://wanip.info/

这将显示您的WAN地址。 xxx.xxx.xxx.xx

this will show your WAN address. xxx.xxx.xxx.xx

这是多少你把你的AJAX请求

this is the number you put in to your AJAX requests

例如

$.ajax({
  method: "POST",
  url: "http://xxx.xxx.xxx.xxx/some.php",
  data: { name: "John", location: "Boston" }
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });

有关Ajax更多资讯

More info about Ajax here

http://api.jquery.com/jquery.ajax/

但首先我们玩完完成一些小的任务

But first we finish off completing some minor tasks

您的路由器需要知道你的webeservers IP地址,以便它可以发送HTTP请求和数据给它。

You router needs to know your webeservers IP address so it can send HTTP requests and Data to it.

如何找到Web服务器的IP和路由器IP地址使用的Linux

How to find the Webserver IP and Routers IP addresses using Linux

命令

您这样的事

eth0      Link encap:Ethernet  HWaddr 08:00:27:87:35:25
          inet addr:192.168.2.15  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe87:3525/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:861 errors:0 dropped:0 overruns:0 frame:0
          TX packets:549 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:125639 (125.6 KB)  TX bytes:63563 (63.5 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:56 errors:0 dropped:0 overruns:0 frame:0
          TX packets:56 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3360 (3.3 KB)  TX bytes:3360 (3.3 KB)

您感兴趣的以太网卡的eth0 (如果你已经安装了多个网卡,你还可以看到(ETH1,ETH2等)和本 INET地址: 192.168.2.15 是您的服务器地址,不是静态然而

You are Interested in the Ethernet Network Card eth0 (if you have installed more than one network card you may also see (eth1, eth2 etc) and this inet addr:192.168.2.15 is your servers address. Not Static Yet

命令

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.2.1     0.0.0.0         UG    0      0        0 eth0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

192.168.2.1 (下网关旁边的 0.0.0.0 )是路由器本地地址

this 192.168.2.1 (under the Gateway next to 0.0.0.0) is the Routers Local Address

请注意,你可能会有所不同。

Please note, yours may be different

打开浏览器并输入在

http://192.168.2.1

http://192.168.2.1

您会psented与你的路由器的主页$ P $。登录并找到虚拟服务器设置。应在常规防火墙选项。

you will be presented with your routers home page. Log in and find Virtual Servers settings. Should be in the General Firewall Options.

您应该看到这样的表

根据您的路由器型号,你应该会看到类似的东西。使用下拉菜单,选择WEB HTTP。单击添加。 80 80 ..这是端口的防火墙将打开Web通信。输入您的Web服务器地址的最后2位数字,然后点击保存。您的路由器可能会重新启动以保存更改。

Depending on your routers model you should see something similar. Use the drop down menu and choose WEB HTTP. Click add. The 80 80 .. that's the ports the firewall will open for WEB communication. Enter the last 2 digits of your web servers address and click Save. Your router may reboot to save the changes.

让安装Samba服务器,这样你可以分享你的网络文件夹到你的本地网络,以便可以从本地PC访问。在这个例子中,我们使用Windows。

Lets install SAMBA server so you can share your web folder to your Local Network so you can access it from a local PC. In this example we use Windows.

命令

在它已完成安装编辑Samba配置文件,这样我们可以添加我们希望在我们的情况下共享的文件夹 /无功/网络/

After it has finished Installing edit the samba configuration file so we can add the folder we want to share in our case /var/www/

命令

转到文件的底部,并添加

go to the bottom of the file and add

[share]
    comment = Ubuntu File Server Share
    path = /var/www/
    browsable = yes
    guest ok = yes
    read only = no
    create mask = 0777

CNTRL X 以保存并退出该文件

CNTRL X and Y to save and exit the file

我建议检查网为Samba共享的配置上面的设置并没有太多考虑安全性。你可以做更多的事情就像要求一个密码才能连接,禁用来宾等。

i suggest checking the net for samba share configuration as the above setup does not have much security in mind. You can do much more like request a password to connect, disable guests, etc.

我们改变的Web文件夹的权限,以充分。虽然不建议,因为你有一个空白的网页文件夹,你应该继承普通用户权限创建文件,当你了解在未来的变化对Linux的文件和目录的权限更改它们。

we change the Permissions of the web Folders to full. Although not recommended, as you have a blank web folder you should inherit normal user permissions as you create files and when you learn about changing permissions of files and directories on Linux in the future you change them.

命令

基本 777 为s $ P $垫入3级别的权限,并重新presents二进制111 /111分之111 - 二进制数(111)是在现实世界中,以便7 READ(1),WRITE(1),EXECUTE(1)全部接通的那些3个级别的哪个其不是很安全。我建议你​​阅读更多关于搭配chmod 命令和文件的权限,以获取有关其使用更深入的了解。

basically the 777 is spread into 3 levels of permissions and it represents binary 111/ 111/111 -- binary number (111) is in the real world 7 so READ(1), WRITE(1), EXECUTE(1) are all turned on for those 3 levels which its not very secure. I suggest you read more about the chmod command and file permissions to get a better understanding about its use.

现在是时候给服务器重新启动

It's time to give the server a Reboot

现在将重新启动完成后,允许连接到共享的网络文件夹

Now The Reboot is done, Lets connect to that shared Web Folder

假设你已经运行连接到同一个本地网络中的Web服务器(苹果机应该是类似的东西,但检查如何连接到共享驱动器)

Assuming you have a PC running windows connected to the same Local Network as the web server (Mac should be something similar but check on how to connect to a shared drive)

打开电脑,选择映射网络驱动器键入Web服务器的IP地址,例如 \\ 192.168.2.23 \ - 点击浏览您应该看到我们的SAMBA配置文件中的共享文件夹。连接到它。

Open Computer, choose Map Network Drive type in the web servers IP address e.g \\192.168.2.23\ - click Browse You should see the folder we shared in the SAMBA configuration file. Connect to it.

款待驱动像任何驱动器来保存您的文件只有这一个是Web服务器的网站的根文件夹(S)的文件夹。

Treat that drive like any drive to save your files only this one is the root folder of your web server website(s) folder.

但在Web服务器上,如果你不想如您想自定义名称为您的网站默认的HTML文件夹,在Windows上右键单击该文件夹并重新命名。

However on the webserver if you don't want the default html folder eg you want a custom name for your website, on windows right click on the folder and rename it.

如果你重新命名它,你需要让阿帕奇知道通过执行以下

If you do rename it you need to let Apache know by doing the following

命令

变更的DocumentRoot的/ var / www / html等的DocumentRoot的/ var / WWW / thenewname

CNTRL X 以退出纳米

重新启动Apache网络服务器采取的变化

restart apache webserver to take in the change

做一个测试页面

写一个简单的index.html网页或index.php的PHP页面并将它保存在Web文件夹

write a simple index.html webpage or index.php php page and save it in the web folder

在您的WAN联系地址打开浏览器,键入

open a browser and type in your WAN adress

下面是关于如何撰写和使用PHP发送电子邮件中的链接

here is a link on how to compose and send an email with PHP

https://css-tricks.com/sending-nice -html-电子邮件与-PHP /

确定最后一个音符

您拥有一切运行,但给每个本地PC自动当他们连接到网络的家庭路由器具有储备的IP地址。不是一个大问题,但它的最大努力给Web服务器的静态IP地址

You have everything running, but Home Routers Have Reserve IP address that give each local PC automatically when they connect to the network. Not a big issue, but its best to give the web server a static IP address

登录到路由器再次转到 LAN设置具体来说,我们要检查的 DHCP服务器 IP池设置。 DHCP是负责为每台PC自动放弃了在本地网络中的IP地址,以便保留围绕这100个出可能的253地址,家庭路由器上。我们需要检查的范围,选择一种以上的范围内。

Log in to your router again and go to your Lan Setup specifically we want to check the DHCP Server IP Pool Settings. Dhcp is responsible for giving out IP address automatically to each PC in a local network so it reserves around 100 of these out of possible 253 address on a home router. We need to check the range and choose one above that range.

您应该看到这样的事情。从192.168.2.2到192.168.2.100的DHCP服务保留。因此,逻辑有它我们可以选择 192.168.2.101 作为地址的服务器,因为这是不使用DHCP服务。事实上 192.168.2.101 192.168.2.254 是免费为路由器的IP地址的完整范围为2〜 254 0,1和255所使用的路由器。

You should see something like this. From 192.168.2.2 to 192.168.2.100 are reserved by the Dhcp service. So logic has it we can choose 192.168.2.101 as an address for the server as this is not used by the Dhcp service. In fact 192.168.2.101 to 192.168.2.254 are free as the complete range of a routers IP address are from 2 to 254 the 0, 1 and 255 are used by the router.

编辑在您的网络服务器的网络文件

edit the network file on your webserver

命令

复制你所看到的下面,(没有 //言论),并删除该配置文件中的现有设置为的eth0 这是以太网卡0。

Copy what you see below, (without the //remarks) and delete the existing setup in the configuration file for eth0 which is the Ethernet card 0.

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.2.101 //the chosen IP address for the webserver
gateway 192.168.2.1  // the routers address
netmask 255.255.255.0 // leave this as is
network 192.168.2.0 // change x.x.2.x if  you are on the 1 network. ie 192.168.1.0 some routers are on the 1 network
broadcast 192.168.2.255 // same as above
dns-nameservers 8.8.8.8 //check below

CNTRL X 以退出纳米

只是为了澄清与DNS域名服务器8.8.8.8使用谷歌公共DNS服务器翻译网页地址为IP地址。它是一种普遍使用的一个。您可以更改为您知道的任何公用DNS地址,但它是必需的,因为我们现在有Web服务器手动设置。

Just to clarify dns-nameservers 8.8.8.8 uses a Google Public DNS server to translate web address to IP addresses. Its a general use one. You can change that to any Public DNS Address you know, but it is required because we now have manual settings for the webserver.

再次重启服务器负载的变化对网络,最后登录到你的路由器并更改IP号码您的虚拟服务器,如图我们前面做了上面的步骤来发送HTTP请求。

Reboot the server again to load in the changes to the network and lastly log in to your router and change the IP number for your Virtual server to send HTTP Requests as shown in the above Step we did earlier.

我希望这个指南可以帮助你

I hope this guide helps you

这篇关于电子邮件对自己用户提交的表单 - 混合应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆