我想在我的 AngularJS 应用程序中提交表单时发送电子邮件。
我的 email.php 文件如下所示:
<?php
$receiver = $_REQUEST['to'];
$subject = "The subject";
$message .= 'Hello';
$header = "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type:text/html;charset=utf-8" . "\r\n";
$header .= "From: mail@mail.com" . "\r\n";
mail($receiver, $subject, $message, $header);
?>
在我的表单上,我有 ng-submit="submit()",这个函数看起来像这样:
var data = "to=" + $('.user-email').val();
$scope.url = "/email.php";
var transform = function(data) {
return $.param(data);
}
$http({
type: "POST",
url: $scope.url,
data: data,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: transform
}).success(function(responseData) {
Console.log('Hurray')
}).error(function(responseData) {
console.log('error');
});
但是,当我按下提交按钮时,出现以下错误:http ://cl.ly/image/1k0E2O0Q3c0B
我究竟做错了什么?