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! –