Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 可以在浏览器上使用URL发送电子邮件,但在浏览器上不起作用_Php_Angular_Email - Fatal编程技术网

Php 可以在浏览器上使用URL发送电子邮件,但在浏览器上不起作用

Php 可以在浏览器上使用URL发送电子邮件,但在浏览器上不起作用,php,angular,email,Php,Angular,Email,如果我在浏览器上调用脚本,它会向我的域电子邮件发送电子邮件。无论如何,我正在尝试从angular 7应用程序发送一些联系人电子邮件。我确实使用了HttpClient post并尝试将数据作为JSON发送。(Apache服务器PHP-V5.6) 我已尝试使用类似mail.php的URL发送数据?param1=”info@test.test“¶m2=“测试电子邮件”。我一点运气都没有。我尝试了文件获取内容(“php://input"); 也不走运 <?php echo("called"

如果我在浏览器上调用脚本,它会向我的域电子邮件发送电子邮件。无论如何,我正在尝试从angular 7应用程序发送一些联系人电子邮件。我确实使用了HttpClient post并尝试将数据作为JSON发送。(Apache服务器PHP-V5.6)

我已尝试使用类似mail.php的URL发送数据?param1=”info@test.test“¶m2=“测试电子邮件”。我一点运气都没有。我尝试了文件获取内容(“php://input"); 也不走运

<?php
echo("called");
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
header('Content-type: application/json');
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Headers: X-Requested-With, content-type, access-control-allow-origin, access-control-allow-methods, access-control-allow-headers');

  // Sanitize.
 // $title = $_GET['title'];;
 // $message = $_GET['message'];;
 // $name    = $_GET['name'];;
 // $from = $_GET['from'];;

  $title = $request->title;
  $message = $request->message;
  $name    = $request->name;
  $from = $request->from;
  $to = "info@test.com";


  // Sending email
  if(mail($to, $title, $message, $name)){
      echo 'Your mail has been sent successfully.';
  } else{
      echo 'Unable to send email. Please try again.';
  }


?>

这是我的发球

export class PollServiceService {

  PHP_API_SERVER: string = "/api";
  constructor(private http: HttpClient) {
   }


  public SendEmail(e: any): Observable<any>{
    var tmp1 = "/?title=" + e.title + "&message=" +e.message + "&name=" +e.name + "&from=" + e.from ;
    return this.http.post<any>(`${this.PHP_API_SERVER}/mail.php`, e);
  }
}
导出类PollServiceService{
PHP_API_服务器:string=“/API”;
构造函数(专用http:HttpClient){
}
公共发送电子邮件(e:any):可观察{
var tmp1=“/?title=“+e.title+”&message=“+e.message+”&name=“+e.name+”&from=“+e.from;
返回this.http.post(`this.PHP\u API\u SERVER}/mail.PHP`,e);
}
}

我确实调用了表单上的sendmail(e:any)方法。无论如何,这似乎对任何事情都没有影响。我怀疑脚本根本没有调用php文件。提前感谢各位。

您的SendEmail函数将返回一个可观察的结果

为了使调用发生,您必须加入这个可观察对象

因此,您应该在组件中的函数中执行类似的操作:

this.pollServiceService.SendEmail(e).subscribe(res => {
    // here you can do whatever you want with the result of the call
});

然后应该从表单中调用此函数。

SendEmail函数返回一个可观察到的值

为了使调用发生,您必须加入这个可观察对象

因此,您应该在组件中的函数中执行类似的操作:

this.pollServiceService.SendEmail(e).subscribe(res => {
    // here you can do whatever you want with the result of the call
});

然后应该从表单中调用此函数。

不客气!如果它是您正在寻找的解决方案,您可以使用绿色复选标记来标记答案@不客气!如果它是您正在寻找的解决方案,您可以使用绿色复选标记来标记答案@el6976