I'm adding a contact form found on a site that could help me on the php side. My Only issue seems to be I can't seem to connect my JS to my PHP in the console I get. Any Ideas on how I can get both to talk to each other and work : ) Thank you :)
angular.js:8661 POST http://localhost:3000/processForm.php 404 (Not Found)
my js http look liks
$scope.sendMessage = function( input ) {
$http({
method: 'POST',
url: 'processForm.php',
data: input,
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' }
})
.success( function(data) {
if ( data.success ) {
$scope.success = true;
} else {
$scope.error = true;
}
});
}
my php looks like
<?php
$response = array( 'success' => false );
$formData = file_get_contents( 'php://input' );
$data = json_decode( $formData );
if ( $data->submit && empty( $data->honeypot ) ) {
$name = $data->name;
$email = $data->email;
$message = $data->message;
if ( $name != '' && $email != '' && $message != '' ) {
$mailTo = '[email protected]';
$subject = 'New contact form submission';
$body = 'From: ' . $name . "\n";
$body .= 'Email: ' . $email . "\n";
$body .= "Message:\n" . $message . "\n\n";
$success = mail( $mailTo, $subject, $body );
if ( $success ) {
$response[ 'success' ] = true;
}
}
}
echo json_encode( $response );
?>
file structure is
│ 404.html
│ favicon.ico
│ index.html
│ robots.txt
│ processForm.php
│
├───images
│ yeoman.png
│
├───scripts
│ │ contact.js
│ │
│ │
│ │
│ └───controllers
├───styles
│ main.css
│ style.css
│
└───views
contact.html
main.html