Urgent! Send Email http php no send data from form


#1

Hi guys, I have to send email without email composer …

the data defined in the controller are sent quietly … but I can not pass the data that is entered into the form… in this controller the parameters are sent … and the mail is sent and received correctly

  .controller('ContactFormCtrl', function ($scope, $http) {
        $scope.invioDati = { email: "", message: "" };
        $scope.onsubmit = function () {
            $http({
                method: 'POST',
                url: 'http://mydomain/client/sendemail.php',
                data: 'email=emailtest%40gmail.com' + '&message=corpodelmessaggiotest' + '&privacy=true',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },

            }).then(function successCallback(response) {
                alert("Email Inviata!");
            }, function errorCallback(response) {
                alert("error with sending a msg");
            });
        }

    });

this is my form

<form name="myForm" ng-controller="ContactFormCtrl" novalidate>

              <label>Email</label>
              <input type="email" name="email" ng-model="invioDati.email" required style="width: 100%; background: #ededed; border: 1px solid #c1c1c1">

              <label>Messaggio</label>
              <textarea name="message" ng-model="invioDati.message" required style="width: 100%; background: #ededed; border: 1px solid #c1c1c1; height: 100px;"></textarea>

              <div class="item" style="text-align: center">
                <p> Autorizzo;</p>
                <label class="toggle">
                  <input name="privacy" ng-model="invioDati.privacy" value="true" type="checkbox" checked required>
                  <div class="track">
                    <div class="handle"></div>
                  </div>
                </label>
              </div>

              <div class="padding">
                <p ng-show="myForm.email.$error.required">* Indirizzo Email Richiesto</p>
                <p ng-show="myForm.email.$invalid && !myForm.email.$pristine">* Inserisci un indirizzo email valido</p>
                <p ng-show="myForm.password.$error.required">* Password is required</p>
                <p ng-show="myForm.message.$error.required">* Il messaggio non può essere vuoto</p>
                <p ng-show="myForm.privacy.$error.required">* Devi Accettare la nostra Privacy Police</p>
              </div>

              <button type="submit" class="button button-block button-dark" on-tap="onsubmit()" ng-disabled="myForm.$invalid">Invia Email</button>

            </form>

this is my sendemail.php

<?php
        header('Access-Control-Allow-Origin: *');
   // Access-Control headers are received during OPTIONS requests
    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']}");
            
            if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST))
    $_POST = json_decode(file_get_contents('php://input'), true);
            

        exit(0);
    }

$email_subject= "Email from App";
$email_from = "email da: ".$_POST["email"];
$message = "Testo Messaggio: ".$_POST["message"];

$to = "myemail@gmail.com";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email."\r\n" .
@mail($to, $email_subject, $email_from, $message, $headers); 

?>

how can I take the data from the form? where am I wrong? thanks


#2

Your invioDati object in the model contains the values, so on onclick you can pass the invioDati object and read it in the controller.

<button type="submit" class="button button-block button-dark" 
on-tap="onsubmit(invioDati)" ng-
disabled="myForm.$invalid">Invia Email</button>

#3

Hello, I have copied the form in my app but it does not work, you know why?


#4

Hi. I do not speak English so I translated it through google.
I used in my project the following and it worked.

$email_subject= "Fale Conosco";
$mens .= "<font size=3><b>Contato enviado pelo aplicativo</b></font>\n<br><br>";
$mens .= "<b>Nome completo:</b> $nome\n<br>";
$mens .= "<b>E-mail:</b> $email\n<br>";
$mens .= "<b>Telefone:</b> $telefone\n<br>";
$mens .= "<b>Assunto:</b> $assunto\n<br>";
$mens .= "<b>Mensagem:</b> $mensagem\n<br>";
$mens .= "<br>:)\n<br>";
$to = "YOUR@EMAILHERE.com";
$headers = "MIME-Version: 1.0\n";
$headers .= "From: \"$nome\" <$email>\r\n";
$headers .= "Cc: $emailcopia\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
//envio o email sem anexo
mail($to,$email_subject,$mens,$headers);

Good luck.