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