2016-02-08 95 views
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'; 
} 
?> 

而这个错误

它的工作原理和发送电子邮件,当我只发送字符串或HTML,但使用回声连接值这些错误发生。

+0

你是在说''message =“Hi”.echo $ username。“welcome to the site ... blabla”;'? 'echo'不应该在那里:'$ message =“Hi”。$ username。“欢迎来到本站... blabla”'; – Jorg

+0

谢谢chris85! –

回答

0

先删除$消息

$message="Hi".$username ." welcome to the site... blabla"; 

前回声使用,并检查您的邮件功能是返回真还是假。如果邮件功能没有返回true,那么你将总是得到“错误”。

相关问题