I've found a tutorial here about using the $http
service to send data to PHP.
I think I understand the syntax for the submission in Angular, but I don't understand how he is getting the variables with $data = file_get_contents("php://input");
It seems like feeding file_get_contents
a random URL?
Regardless, here is as far as I got. This is intended to send an email without a refresh. I'm not interested in returning anything right now, I just want to send the email.
HTML:
<script type="text/javascript" src="http://allenhundley.com/js/contact/contact.js"></script>
<div id="format">
<div id="header">
</div>
<p id="text">
Have any questions? Have a project? Shoot me an email here or at Allen@AllenHundley.com.
</p>
<br />
<input class="input" type="email" ng-model="email" placeholder="Email"/>
<input class="input" type="text" ng-model="subject" placeholder="Subject"/>
<textarea id="message" ng-model="message" placeholder="Message"></textarea>
<button id="send" name="send" ng-click="emailCtrl.send()">Send Email</button>
</div>
AngularJS:
var emailController = spa.controller("emailController", ["$scope", "$http", function($scope, $http) {
this.send = function() {
$http.post('/php/send_email.php', {
email : $scope.email,
subject : $scope.subject,
message : $scope.message
});
};
});
PHP:
<?php
$user_email = $_POST["email"];
$user_subject = $_POST["subject"];
$user_message_input = $_POST["message"];
$user_headers = 'MIME-Version: 1.0\r\n';
$user_headers .= 'Content-type:text/html;charset=UTF-8\r\n';
$user_headers .= 'From: <noReply@AllenHundley.com>\r\n';
$user_message = "
<html>
<head>
<title>
Thanks for contacting me!
</title>
</head>
<body>
" . $user_message_input . "
</body>
</html>
";
mail($user_email, $user_subject, $user_message, $user_headers);
$developer_to = "Allen@AllenHundley.com";
$developer_subject = $user_subject;
$developer_message = $user_message_input;
$developer_headers = 'MIME-Version: 1.0\r\n';
$developer_headers .= 'Content-type:text/html;charset=UTF-8\r\n';
$developer_headers .= 'From: <' . $user_email . '>\r\n';
$user_message = "
<html>
<head>
<title>
Thanks for contacting me!
</title>
</head>
<body>
" . $developer_message . "
</body>
</html>
";
mail($developer_to, $developer_subject, $developer_message, $developer_headers);
?>
I've tried to read the documentation on $http
but I think I already have that part right. It doesn't say anything about PHP.
Where do I go from here?