使用AngularJs,尝试通过Google App Engine上的PHP使用HTML联系我们表单发送电子邮件
using AngularJs, trying to send email using an HTML Contact-Us Form via PHP on Google App Engine
下面是我的联系表单的html代码
<div class="col">
<h3>Say hello</h3>
<div ng-show="error" class="error">
<p>Something wrong happened!, please try again.</p>
</div>
<form method="post" role="form" ng-submit="sendMessage(input)" class="contactForm" name="form" id="contact_form" >
<input type="text" name="firstname" id="firstname" placeholder="Name" required="required" ng-model="input.name">
<input type="text" name="telephone" id="telephone" placeholder="Telephone" required="required" ng-model="input.telephone">
<input type="text" name="email" id="email" placeholder="Email" required="required" ng-model="input.email">
<textarea name="comments" maxlength="1000" cols="20" rows="3" placeholder="Comment" required="required" ng-model="input.message"></textarea>
<button type="submit" name="submit" value="submit" ng-disabled="!form.$valid">Submit</button>
</form>
<!-- <div ng-show="process" style="text-align:center">
<img class="loader" src="" />
Sending ...
</div> -->
<div ng-show="success" class="success">
<p>Thank you for taking the time to contact us</p>
<p>Have A Great Day!</p>
</div>
<div class="clearboth"></div>
</div>
我的代码来自应用程序.js
var app = angular.module('example', []).
run(['$rootScope', '$http', '$browser', '$timeout', "$route", function ($scope, $http, $browser, $timeout, $route) {
$scope.sendMessage = function( input ) {
input.submit = true;
$scope.success = false;
$scope.error = false;
$scope.loaded = true;
$scope.process = true;
$http({
method: 'POST',
url: 'js/sendemail.php',
data: input,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
})
.success( function(data) {
if ( data.success ) {
$scope.success = true;
$scope.process = false;
$("form").trigger("reset");
} else {
alert("error :" +data);
$scope.error = true;
}
});
};
下面是我的发送电子邮件.php代码
<?php
$response = array( 'success' => false );
$formData = file_get_contents( 'php://input' );
$data = json_decode( $formData );
if ( $data->submit ) {
$name = $data->name;
$email = $data->email;
$telephone = $data->telephone;
$message = $data->message;
if ( $name != '' && $email != '' && $message != '' && $telephone != '') {
$mailTo = 'xxx@gmail.com';
$subject = 'New Contact Form Submission';
$body = 'From: ' . $name . "'n";
$body .= 'Email: ' . $email . "'n";
$body .= 'Telephone: ' . $telephone . "'n";
$body .= "Message:'n" . $message . "'n'n";
$success = mail( $mailTo, $subject, $body );
if ( $success ) {
$response[ 'success' ] = true;
} else {
$response[ 'success' ] = false;
}
}
}
echo json_encode( $response );
?>
我已经将日志保存在JavaScript sendMessage函数中,以检查数据是否来自html。是的,它来了。我可以在警报消息中看到数据。
我已经浏览了许多链接并更新了Google App Engine ->设置 ->电子邮件地址。
当我单击表单中的提交按钮时。我可以看到我在JS警报中编写的警报消息("错误" +数据);警报框由整个 php 代码组成。
下面是我的app.yaml文件
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: static/index.html
upload: static/
- url: /images
static_dir: static/images
- url: /css
static_dir: static/css
- url: /js
static_dir: static/js
- url: /pages
static_dir: static/pages
- url: /static
static_dir: static
- url: /(.+'.php)
script: '1
- url: /.*
script: start.application
有人可以帮助我解决这个问题吗?
而不是PHP,尝试使用Google App Engine mail API for python应用程序:send-mail-with-mail-api,你仍然可以使用Angular进行数据绑定。
相关文章:
- 我已经创建了一个jquery转盘,并使用if条件来运行和停止转盘
- 为什么使用immutableJS我的状态没有改变
- 将broccoliJS与当前使用requireJS的模块化主干应用程序结合使用,我想完全放弃requireJS
- 如何使用 javascript 按列对表进行排序?不能在这里使用 jquery.我正在使用javascript从xml文
- 浮动左侧按钮,用于呼叫我和联系我
- 如何在谷歌工作表中使用数组公式时使用getLastRow.我可以让它忽略一列吗
- 在 AngularJS 中使用数据库 - 我应该在哪里编写数据库连接代码
- Ajax不使用javascript.我应该怎么做
- 其他人怎么能使用和我相同的命名空间呢
- 如何使用Captcha我的代码
- Dojo DataGrid过滤器使用AndOrReadStore-我做错了什么?.
- AJAX调用使用了我所有的web主机的内存和I/O
- 而获取JSON数据使用ajax我得到意外令牌:错误
- Javascript对象名称使用问题.我认为
- AngularJS-我如何使用在我的控制器中使用Factory GET请求检索的数据
- 我使用Push()数组被使用,我试图从下拉菜单中选择一个列表,并将该列表发布到一个跨度中
- 使用RequireJS:我应该定义继承的资源吗?
- 使用:display_as -我如何更新还有
- 如何在变量中使用foreach?我被卡住了
- 当您不使用'我不知道身份证