I am creating an application using AngularJS and PHPMailer. I need to pass an array from my Angular application to PHPMailer, and then get the array in PHPMailer and send data to the client.
$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); });
Here $ scope.listItems is an array consisting of header fields such as client name, client email, client phone, etc. and lots of data under each heading. So it comes down to $ scope.listItems.customerName, $ scope.listItems.customerPhone, etc. I get data in Angular very easily, using Angular for everyone.
I managed to transfer the data to PHPMailer, but I have no idea how to get the data into PHPMailer and send it by mail.
UPDATE
PHPMailer Code
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 = " support@uvw.com "; $mail->Password = " support@123 "; $mail->From = " support@uvw.com "; $mail->FromName = "uvw"; $mail->AddAddress(" orders@uvw.com ", "Orders"); $mail->WordWrap = 50; $mail->IsHTML(true); $mail->Subject = "New Customer"; $mail->Body = $body; $mail->AltBody = "Alternate Body"; if(!$mail->Send()) { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; } echo "Message has been sent"; } else { echo "Could not Mail"; }
$ scope.listItems datastructue
$scope.listItems.customerName, $scope.listItems.customerEmail, $scope.listItems.customerPhone, $scope.listItems.customerAddress
source share