0
我有一个角度文件,它发送一个邮件请求发送变量(电子邮件,用户,keysuser)到PHP文件发送电子邮件。但是当我使用echo来打印值时,响应是一个错误。让我告诉你:为什么header允许跨域不允许使用echo来输出变量值?
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With');
header('Access-Control-Allow-Credentials: true');
$data = file_get_contents("php://input");
$dataJsonDecode = json_decode($data);
$email = $dataJsonDecode->email;
$username = $dataJsonDecode->username;
$id = $dataJsonDecode->keyuser;
$subject = "Welcome";
$message="Hi".echo $username ." welcome to the site... blabla";
$header .= 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= 'From: GoVir <[email protected]>' . "\r\n";
if(mail($email,$subject,$message,$header)){
echo 'success';
}else{
echo 'Error';
}
?>
而这个错误
- MLHttpRequest无法加载http://www.govircarpool.com/correo/correo.php。请求的资源上没有“Access-Control-Allow-Origin”标题。因此不允许访问原产地'http://localhost:8100'。回应有HTTP状态代码500. *
它的工作原理和发送电子邮件,当我只发送字符串或HTML,但使用回声连接值这些错误发生。
你是在说''message =“Hi”.echo $ username。“welcome to the site ... blabla”;'? 'echo'不应该在那里:'$ message =“Hi”。$ username。“欢迎来到本站... blabla”'; – Jorg
谢谢chris85! –