[英]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>
我来自app.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;
}
});
};
下面是我的sendemail.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 alert(“ error” + data)编写的警报消息; 警报框包含整个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
有人可以帮我解决这个问题。
尝试使用Google App Engine邮件API(而不是PHP)代替python应用程序: sending-mail-with-mail-api ,您仍然可以使用Angular进行数据绑定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.