2013-05-14 5 views
0

을 잘립니다. 나는 HTML 및 일반 텍스트 PHP로 생성 일부 콘텐츠를 전송하기 위해 노력하고있어,하지만 몸은 잘립니다. 무엇도 낯선 것은 내가 거기에 훨씬 더 큰 길이 몇 가지 일반적인 내용을 넣을 경우이 만 내가 생성 이메일에 일어나는 것입니다, 그것은 제대로 전송됩니다. 나는 모두 $content$nohtmlcontent 변수의 내용을 에코했고, 모든 것을 거기에 그것이 있어야 좋아하지만, 내 사서함으로 메일을받을 때,이 잘릴 것입니다, 또한 언급해야합니다.PHPMailer 몸은 내가 PHPMailer 몇 가지 이상한 문제에 봉착

$content="<BODY bgColor=\"#ffffff\"><FONT face=\"Verdana\" size=\"2\">"; 
$content.="Hello $name.<br /><br />Administrator of <a href=\"http://$url\">$url</a> has created a new account for you.<br /><br />Your new account details:<br />"; 
$content.=$message."<br /><br />"; 
$content.="If you see something wrong, please reply with correct details and we will update your account.<br /><br />"; 
$content.="Have a nice day,<br />$url</FONT></FONT></BODY>"; 

$nohtmlcontent="Hello $name.\n\nAdministrator of $url has created a new account for you.\n\nYour new account details:\n\n"; 
$nohtmlcontent.=$usrEmail."\n\n"; 
$nohtmlcontent.="If you see something wrong, please reply with correct details and we will update your account.\n\n"; 
$nohtmlcontent.="Have a nice day,\n$url"; 

모든 변수는 해당 데이터로 채워집니다 : 일반 텍스트 및 HTML 이메일 몸을 만들기위한

내 PHP 코드입니다. 이메일을 보내는

내 PHPMailer 코드 :

require_once("class.phpmailer.php"); 
$mail=new PHPMailer(true); 
try { 
    $mail->AddAddress($email); 
    $mail->SetFrom('[email protected]', 'example.com'); 
    $mail->CharSet = 'UTF-8'; 
    $mail->Subject = "New account for you"; 
    $mail->IsHTML(true); 
    $mail->AltBody = $nohtmlcontent; 
    $mail->Body = $content; 
    $mail->Send(); 
    return true; 
}catch(phpmailerException $e){ 
    trigger_error("PHPMailer failed: ".$e->errorMessage()); 
    return false; 
} 

결과 :

Hello 12 23. 

Administrator of admin.localhost.dev has created a new account for you. 

Your new account details: 
Username: user1 
Password: 123456 
E-Mail Address: [email protected] 
Subscription Status: Not Verified (you must verify your email address before you can use your account) 
Package: Free (limitations: 1 tour, 5 items) 
First Name: 12 
Last Name: 23 
City 34 
Country 45 

Your verification link: http://admin.localhost.dev/verify-account/882672636ce2ad8c498f75a9b836ff055aecf573/ 

If you see something wrong, please reply with correct details and we will update you 

예상 결과 :

Hello 12 23. 

Administrator of admin.localhost.dev has created a new account for you. 

Your new account details: 
Username: user1 
Password: 123456 
E-Mail Address: [email protected] 
Subscription Status: Not Verified (you must verify your email address before you can use your account) 
Package: Free (limitations: 1 tour, 5 items) 
First Name: 12 
Last Name: 23 
City 34 
Country 45 

Your verification link: http://admin.localhost.dev/verify-account/882672636ce2ad8c498f75a9b836ff055aecf573/ 

If you see something wrong, please reply with correct details and we will update your account. 

Have a nice day, 
admin.localhost.dev 

결국 추가 내용을 통지하시기 바랍니다. 나는 또한 동일한 콘텐츠를 전송하는 PHP의 기능 mail()를 사용하여 시도했다

, 그것은 또한 잘립니다.

아이디어가 있으십니까?

해결 방법 : PHP 코드는 몇 줄 바꿈 문자를 추가 한 후 정말로 긴 줄을 생성하여 전체 내용을 처리했습니다.

답변

1

은 또한이 관련이되지 않을 수 있습니다하지만 당신은

$mail->Body = $content; 

몸과하지 MsgHTML

를 사용하지만, 그것은 당신의 콘텐츠에 HTML 표현을 사용하는 것 같습니다.

나는 이것에 비교적 새로운 해요하지만 텍스트가 잘 표시되어 있고이 문제를 해결 좋아 보이지만 나는 PHPMailer에 HTML을 사용하여 읽은에서 당신은

$mail->MsgHTML = $content; 

를 사용해야합니다. 하지만 도움이된다면 나누겠다고 생각했습니다.

여기에 몇 가지 유용한 정보 https://phpbestpractices.org/ 여기

과 (정보를 이메일로 아래로 스크롤) : ( https://github.com/PHPMailer/PHPMailer

+0

내가 모든 예제에,'$ 메일 ->이 MsgHTML' 사용할 수 있다는 걸 몰랐와 내가 본 SO 질문/답변) 나는 항상주의'$ 메일 -> Body'하지만'$ 메일 -> IsHTML (참)', 이전에 제공 그렇지 않으면 PHPMailer는 내용이 일반 텍스트 잘못된'콘텐츠 형식이라고 가정해야한다 '보내집니다. –