0

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

1 Answer 1

1

From your directory stucture I guess that you are using Yeoman angular generator and built in server. Please make sure that you are able to access php scripts at all.

You might to reference this post

How to integrate PHP with yeoman angular project

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.