我试图发送一封带有换行符的电子邮件,但每次我添加'r'n
时,它都会不断抛出错误,有人知道它为什么这么做吗?
错误
警告:输入中出现意外字符:中的"''"(ASCII=92)状态=1/第24行上的home3/hutch/public_html/server1/ForgotPassword.php
警告:第24行/home3/hutch/public_html/server1/ForgotPassword.php中的输入中存在意外字符:"''"(ASCII=92)state=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!';
}
}
?>
您需要''r''n用双引号括起来,如"''r''n"。
因为它是要添加到邮件内容中的字符串的一部分。
我必须强调使用双引号而不是单引号,因为单引号不会解析转义符,只会打印''r''n而不是换行符。
使用换行符PHP_EOL的系统属性怎么样。使用PHP_EOL常量,该常量会自动设置为运行PHP脚本的操作系统的正确换行符。
注意,这个常量是从PHP 5.0.2开始声明的。