我正在使用AngularJS和PHPMailer构建一个应用程序.我需要将一个数组从我的Angular应用程序传递给PHPMailer,然后在PHPMailer中检索数组并将数据邮寄到客户端.
$scope.data = {};
var link = 'http://uvw.com/mail.php';
$http.post(link, {order:$scope.listItems}).then(function (res){
$scope.response = res.data;
console.log($scope.response);
});
Run Code Online (Sandbox Code Playgroud)
这里,$ scope.listItems是一个数组,包括客户名称,客户电子邮件,客户电话等主要字段以及每个头下的大量数据.所以归结为$ scope.listItems.customerName,$ scope.listItems.customerPhone等.我使用angular forEach非常容易地检索Angular中的数据.
我已成功将数据传递给PHPMailer,但我不知道如何在PHPMailer中检索数据并将其邮寄给它.
UPDATE
PHPMailer代码
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers:
{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
$postdata = file_get_contents("php://input");
if (isset($postdata)) {
$request = json_decode($postdata);
foreach ($order as $value) {
$body=$order;
}
require("PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;
$mail->Username …Run Code Online (Sandbox Code Playgroud)