2016-04-29 22 views
0

我試圖發送一封電子郵件與幾個換行符,但每次我添加\r\n,它不斷吐出一個錯誤,任何人都知道它爲什麼這樣做?將換行符添加到電子郵件時出現警告錯誤?

錯誤

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home3/hutch/public_html/server1/ForgotPassword.php on line 24

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home3/hutch/public_html/server1/ForgotPassword.php on line 24

Parse error: syntax error, unexpected T_STRING in /home3/hutch/public_html/server1/ForgotPassword.php on line 24

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  = "[email protected]"; 
      $mail->FromName = "Online Game"; 
      $mail->AddAddress("[email protected]"); 

      $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

你忘記了報價。是$ var = $用戶名 「\ n」 「你好。」; –

回答

0

你需要用\ r \ n的,如 「\ r \ n」 個雙引號。

由於它是要添加到郵件內容中的字符串的一部分。

而且我必須強調使用雙引號而不是單引號,因爲單引號不會解析轉義字符\,而只會打印\ r \ n而不是換行符。

0

如何使用新的行字符PHP_EOL的系統屬性。 使用PHP_EOL常量,該常量會自動設置爲運行PHP腳本的操作系統的正確換行符。

請注意,這個常量是從PHP 5.0.2開始聲明的。

相關問題