नहीं भेजता है, मैं अपने पृष्ठ पर एक संपर्क फ़ॉर्म से एक ईमेल भेजने की कोशिश कर रहा हूं, मैं इसे अपने ईमेल पर भेजने के लिए एक PHP स्क्रिप्ट का उपयोग कर रहा हूं, मैं this ट्यूटोरियल का अनुसरण कर रहा हूं, I मैंने उसका उदाहरण इस्तेमाल किया है और यह काम करता है ... लेकिन मुझे लगता है कि यह मेरे आवेदन में काम करने के लिए प्रतीत नहीं होता है, मुझे पहले 404
त्रुटियों के साथ कुछ परेशानी हो रही थी, लेकिन फिर मैंने अपनी साइट प्रकाशित की और इसे लाइव सर्वर पर रखा और अब मैं सफलता कोडईमेल एंगुलर 4 और PHP
लेकिन ऐसे ईमेल प्राप्त हो नहीं im हो रही है, तो मैं http://mysite/assets/email.php के पास गया और मैं इस त्रुटि
देखकरget-में-touch.component.ts
import { Component, OnInit } from '@angular/core';
import { AppService, IMessage } from '../../services/email.service';
@Component({
selector: 'app-get-in-touch',
templateUrl: './get-in-touch.component.html',
styleUrls: ['./get-in-touch.component.scss'],
providers: [AppService]
})
export class GetInTouchComponent implements OnInit {
message: IMessage = {};
constructor(
private appService: AppService
) { }
ngOnInit() {
}
sendEmail(message: IMessage) {
this.appService.sendEmail(message).subscribe(res => {
console.log('AppComponent Success', res);
}, error => {
console.log('AppComponent Error', error);
});
}
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule, Routes, ActivatedRoute, ParamMap } from '@angular/router';
import { AppComponent } from './app.component';
import { GetInTouchComponent } from './get-in-touch/get-in-touch.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { httpModule } from @angular/forms;
export const ROUTES: Routes = [
{ path: 'get-in-touch', component: GetInTouchComponent }
];
@NgModule({
declarations: [
AppComponent,
GetInTouchComponent
],
imports: [
BrowserModule,
RouterModule.forRoot(ROUTES),
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
email.service.ts
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Resolve } from '@angular/router';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
export interface IMessage {
name?: string;
email?: string;
message?: string;
}
@Injectable()
export class AppService {
private emailUrl = '../app/get-in-touch/email.php';
constructor(private http: Http) {
}
sendEmail(message: IMessage): Observable<IMessage> | any {
return this.http.post(this.emailUrl, message)
.map(response => {
console.log('Sending email was successfull', response);
return response;
})
.catch(error => {
console.log('Sending email got error', error);
return Observable.throw(error);
});
}
}
email.php
<?php
header('Content-type: application/json');
$errors = '';
if(empty($errors)){
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$from_email = $request->email;
$message = $request->message;
$from_name = $request->name;
$to_email = $from_email;
$contact = "<p><strong>Name: </strong> $from_name</p><p><strong>Email:</strong> $from_email</p>";
$content = "<p>$message</p>";
$website = "Thirsty Studios";
$email_subject = "Contact Form";
$email_body = '<html><body>';
$email_body .= '$contact $content';
$email_body .= '</body></html>';
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: $from_email\n";
$headers .= "Reply-To: $from_email";
mail($to_email,$email_subject,$email_body,$headers);
$response_array['status'] = 'success';
$response_array['from'] = $from_email;
echo json_encode($response_array);
echo json_encode($from_email);
header($response_array);
return $from_email;
} else {
$response_array['status'] = 'error';
echo json_encode($response_array);
header('Location: /error.html');
}
?>
मैंने पहले (कोणीय + PHP) इस तरह कुछ भी कभी नहीं किया है, लेकिन मैं सब कुछ ट्यूटोरियल में कहा जाता है कि किया है और मैं समझ नहीं कर पा रहे काम करने के लिए, किसी भी मदद की सराहना की जाएगी और अगर आपको अधिक जानकारी की आवश्यकता है तो कृपया मुझे बताएं
क्या आप वास्तव में इस URL को http: // localhost: 4200/app/get-in-touch/email.php तक पहुंच सकते हैं, क्योंकि आपके पास 404 त्रुटि है। – ksoni
अरे हाँ, मैंने उस यूआरएल तक पहुंचने की कोशिश की और यह काम नहीं किया, इसलिए मैंने जो किया था, वह मेरे संपत्ति फ़ोल्डर में email.php को स्थानांतरित कर दिया गया था और मैं इसे एक्सेस करने में सक्षम था .. लेकिन मुझे अभी भी वही त्रुटि मिल रही है सोच रहा है कि यह काम नहीं कर रहा है क्योंकि मैं लोकलहोस्ट पर हूं? – A61NN5
पृष्ठ का पूरा URL क्या है जहां फ़ॉर्म प्रदर्शित होता है? – ksoni