I'a試圖從PHP發送功能發送電子郵件,它是發送電子郵件,但不與任何數據填充此,它是空角4和PHP電子郵件發送
我的代碼 這是發送服務角。在這裏我有消息的所有數據,從我的形式
export interface IMessage {
name?: string,
telephon?: string,
message?: string
}
@Injectable()
export class AppService {
private emailUrl = '../assets/contact.php';
constructor(private http: Http) {
}
sendEmail(message: IMessage): Observable<IMessage> | any {
JSON.stringify(message); // also tried without it
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)
})
}
}
PHP代碼
<?php
header('Content-type: application/json');
$errors = '';
if(empty($errors))
{
$postdata = file_get_contents("php://input"); // here I have null
$request = json_decode($postdata); // here I have null checked in console
$from_email = $request->email;
$message = $request->message;
$from_name = $request->name;
$to_email = '[email protected]';
$contact = "<p><strong>Name:</strong> $from_name</p>
<p><strong>Email:</strong> $from_email</p>";
$content = "<p>$message</p>";
$website = 'My Wicked Awesome Website';
$email_subject = "$website: Received a message from $from_name ";
$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;
$response_array['MESSAGE'] = $message;
$response_array['POSTDATA'] = $postdata;
$response_array['REQUEEST'] = $request;
e
cho 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');
}
?>
那麼什麼想法? 感謝
我發現一個問題,一切都很好 一個問題是sendEmail服務得到空消息 –