下面是我的联系表单的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进行数据绑定。