I want to create a contact form so that users can send emails directly from the website to my email address. The problem iam having is that it doesn't work no matter what script or guide i used.
I hope someone can take a look and tell me what iam doing wrong here.
What I have tried:
Now i cleaned my code so that it is easier to see if something is wrong so i don't have anything to validate the input text.
what i currently have are 3 files in my server which are contact.php, contact.html and app.js and i created an email account on the same server because it is part of the package when i hosted it.
My html code:
<div class=" container formcontainer">
<form method="post">
<input type="text" name="subject" class="form-control" placeholder="Subject..." ng-model="formData.subject">
<input type="email" name="email" class="form-control" placeholder="Your email..." ng-model="formData.email">
<textarea rows="5" cols="50" class="form-control" placeholder="You message" ng-model="formData.message"></textarea>
<button type="submit" ng-click="processForm()" class="btn btn-success btn-lg btn-block">Submit!</button>
</form>
</div>
My controller:
app.controller("contactController", ['$scope', '$http', function ($scope, $http) {
$scope.formData = {
subject: '',
email: '',
message: ''
};
console.log(formData);
$scope.processForm = function () {
$http({
method: 'POST',
url: 'contact.php',
data: $scope.formData,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
})
};
} ]);
My php script:
<?php
$post_data = file_get_contents("php://input");
$data = json_decode($post_data);
$to = "lurtze@hotmail.com";
$subject = $data['subject'];
$userEmail=$data['email'];
$message=$data['message'];
$headers = 'From: ' . $userEmail . "\r\n" .
'Reply-To:'.$userEmail . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo "Thank you for contacting us!";
}
?>