Email sending with angularJs and PHP

1

Good evening, I'm having trouble sending emails using angularJs and PHP. I'm using PHP's angular and mail (http) service. In the network section it tells me that the form was sent but the email never arrives. If anyone knows a way to solve this, it would be very helpful, thank you very much.

AngularJs driver:

    angular.module('pandu').controller('ContactCtrl', ['$scope', '$http', ContactCtrl]);

    function ContactCtrl($scope, $http) {

        $scope.master = {};
        $scope.user = {};

        $scope.submit = function(){
            console.log($scope.user);
            $scope.method = 'POST';
            $scope.url = 'send_email.php';

            $scope.request = $http({
                method : 'POST',
                url : $scope.url,
                data : $.param($scope.user),
                headers : {'Content-Type' : 'application/x-www-form-urlencoded'}
            }).success(function(response) {
                    $scope.codeStatus = response.data;
                    console.log("success",response);
                }).
                error(function(response) {
                    $scope.codeStatus = response || "Request failed";
                    console.log("error",response);
                });

            console.log("$scope.request",$scope.request);
        };
    }

send_email.php:

<?php
    $errors = array();      
    $response = array();    
    $post_date = file_get_contents("php://input");
    $data = json_decode($post_date);

    $to  = '[email protected]';
    $from = $_POST['email'];
    $name = $_POST['name'];
    $message = $_POST['message'];   
    $asunto = "Mensaje enviado por: $name ".$name;

    var_dump($to);
    var_dump($from);
    var_dump($name);
    var_dump($message);
    var_dump($asunto);

    if (empty($name)) {
        $errors['name'] = 'Name is required.'; 
    }
    if (empty($from)) {
        $errors['email'] = 'E-mail is required.';
    }
    if (empty($message)) {
        $errors['message'] = 'Message is required.';
    }
    if ( !empty($errors)) {
        $response['success'] = false;
        $response['errors']  = $errors;
    } 
    else {
        // Para enviar un correo HTML, debe establecerse la cabecera Content-type
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        // Cabeceras adicionales
        $headers .= 'To: Email <'.$to.'>' . "\r\n";
        $headers .= 'From: Recordatorio '.$from.'<'.$from.'>' . "\r\n";
        $headers .= 'Cc: '.$from. "\r\n";
        $headers .= 'Bcc: '.$from. "\r\n";
        $headers .= 'X-Mailer: PHP/' . phpversion();
        if(mail($to, $asunto, $message, $headers)) {
            $response['success'] = true;
            $response['message'] = 'Thank you for sending e-mail.';
        } else  {
            $response['errors']  = $errors;
        }
    }
    echo json_encode($response);
?>

Network:

    
asked by Antonella Di Virgilio 02.09.2017 в 07:20
source

0 answers