I have built an Angular app, mainly it serves static pages and one of the pages I have is "Contact us". On that page, there is a contact us form where users can fill this in and hit submit button like the following screenshot.
The submit button should initialize a request to the back-end that (PHP) that I am trying to add to my Angular app. The back-end does not exist yet!
Can anyone help me to plug in a PHP back-end into my Angular app, so when I deploy my app and get the dist folder, the back-end api or the php function would be there as well?
Currently, what I have in my angular is a service like the following:
SendEmail(model: any): Observable<boolean> {
const requestUrl = `${this.baseUrl}/send-email`;
return this.http.post<boolean>(requestUrl, JSON.stringify(model), environment.httpOptions);
}
The back-end (PHP) api should look like this:
<?php
if (isset($_POST['submit'])) {
$to = $_POST['email'];
$subject = $_POST['svc'] + " - " + $_POST['name'] + $_POST['lastName'];
$message = $_POST['message'];
$from = "xxx@mydomain.com";
$headers = "From:" . $from;
if (mail($to, $subject, $message, $headers)) {
return true;
}
return false;
}
?>
this service gets called when the user hits the submit button. Also, I am hosting on GoDaddy and I do have SMTP server setup and ready to go.
source https://stackoverflow.com/questions/71517433/how-to-integrate-php-with-my-angular-app

No comments:
Post a Comment