title: PHP Script not found : GET Http://localhost4200/contact/sendmail.php 404 (Not Found)
body: <p>I have an Angular 5 app that I want to run locally before attempting to deploy it on Internet.</p>
  
  <p>I have a <code>contact</code> component in order to receive email from Users via a contact form. In the component folder I have a PHP script <code>sendmail.php</code> that is called when I click on my form button.</p>
  
  <p>Here is the global structure :</p>
  
  <pre><code>MyProjectName
  ----- src
  ----- ----- app
  ----- ----- ----- contact
  ----- ----- ----- ----- contact.component.html
  ----- ----- ----- ----- contact.component.scss
  ----- ----- ----- ----- contact.component.spec.ts
  ----- ----- ----- ----- contact.component.ts
  ----- ----- ----- ----- sendmail.php
  </code></pre>
  
  <p>In the <code>contact.component.html</code> I call a function <code>sendEmail()</code> on the click :</p>
  
  <pre><code>contact.html
  
      &lt;button type="submit" (click)="sendEmail()"&gt;Send&lt;/button&gt;
  </code></pre>
  
  <p>Here is the function in the <code>contact.component.ts</code> file</p>
  
  <pre><code>export class ContactComponent implements OnInit {
  
       constructor(private sendMailService:SendMailService) { }
  
       sendEmail():void {
            this.sendMailService.performGetEx().subscribe();
       }
  </code></pre>
  
  <p>And the service <code>send-mail.service.ts</code>that call the php script. This service is located at the same level as the <code>contact</code> folder <strong><em>and it seems that the error on the path occurs here</em></strong></p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import {HttpClient, HttpHeaders} from '@angular/common/http';
  import { Observable } from 'rxjs';
  
  @Injectable()
  export class SendMailService {
  
  constructor(private http:HttpClient) { }
  
  performGetEx():Observable&lt;any&gt; {
       return this.http.get&lt;any&gt;('./contact/sendmail.php');
  }
  </code></pre>
  
  <p>Each Time I click on my form button here is the Error :</p>
  
  <blockquote>
    <p>GET <a href="http://localhost:4200/contact/sendmail.php" rel="nofollow noreferrer">http://localhost:4200/contact/sendmail.php</a> 404 (Not Found)    zone.js:2935</p>
    
    <p>ERROR HttpErrorResponse {headers: HttpHeaders, status: 404, statusText: "Not 
      Found", url: "<a href="http://localhost:4200/contact/sendmail.php" rel="nofollow noreferrer">http://localhost:4200/contact/sendmail.php</a>", ok: false, …}</p>
  </blockquote>
  
  <p>Is it really a path Error ? is Angular Cli server able to get php script ?</p>
  
  <p><strong>UPDATE :</strong></p>
  
  <p>I deployed my Angular project with Wamp Server ( By the way all my style are KO I don't know if it's normal ?) and I wasn't able to call my script on the click until I added the <code>action</code> property on my form :</p>
  
  <pre><code>contact.component.html
  
  &lt;form action= "sendmail.php" method="post"&gt;
  ...
  &lt;/form&gt;
  </code></pre>
  
  <p>I did the same without Wamp and I have the same issue.</p>