我正在尝试发送一封包含几个换行符的电子邮件,但每次添加\r\n
并且它一直在发出错误时,任何人都知道它为什么会这样做?
错误
警告:输入中出现意外字符:'\'(ASCII = 92)state = 1 in 第24行/home3/hutch/public_html/server1/ForgotPassword.php
警告:输入中出现意外字符:第24行/home3/hutch/public_html/server1/ForgotPassword.php中的'\'(ASCII = 92)状态= 1
解析错误:语法错误,第24行/home3/hutch/public_html/server1/ForgotPassword.php中的意外T_STRING
PHP
<?php
if (isset($_GET['Username'])){
$Username = $_GET['Username'];
if (is_dir("USERS/".$Username) === true) {
$myFile=fopen("USERS/".$Username."/Password.txt","r") or exit("Can't open file!");
$Password = fgets($myFile);
fclose($myFile);
require("PHP/class.phpmailer.php");
require("PHP/class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.sulmaxmarketing.com";
$mail->From = "matt@sulmaxcp.com";
$mail->FromName = "Online Game";
$mail->AddAddress("sulmaxcp@gmail.com");
$mail->Subject = "Forgot Password";
$mail->Body = "You have requested your login details, if this is incorrect please reply to this email letting us know your account has been compromised.".\r\n."Username: ".$Username.\r\n."Password:".$Password;
if(!$mail->Send()) {
echo 'Failed to send password to email. Please contact support.';
}
else {
echo 'An email has been sent to your email address associated with the account.';
}
}
else {
echo 'Username not found!';
}
}
?>
答案 0 :(得分:0)
你需要用&#34; \ r \ n&#34;等双引号括起\ r \ n。
因为它是您要在邮件内容中添加的字符串的一部分。
我必须强调使用双引号而不是单引号,因为单引号不会解析转义字符\并且只会打印\ r \ n而不是换行符。
答案 1 :(得分:0)
如何将系统属性用于新行字符PHP_EOL。 使用PHP_EOL常量,该常量自动设置为运行PHP脚本的操作系统的正确换行符。
请注意,此常量从PHP 5.0.2开始声明。