2012-02-08 2 views
0

지난 2 년 동안 FPDF를 사용하여 PDF 파일을 생성했습니다. 이 파일이 생성되면 전자 메일로 보내드립니다. 최근에 새 서버에 똑같은 스크립트를 설치했습니다. 하나 또는 다른 이유로 PDF 생성은 오류 메시지가 나타나지 않기 때문에 작동합니다. 내가 이메일로 수신 메시지는 바로 텍스트이며, 다음과 같습니다전자 메일 용 FPDF 생성 첨부 파일이 이상한 문자로 구성됩니다.

--4aca5942d8bd7e7d523d8b2d71c6b1ea-- 또는 --d7582bf6769dd1fa2ee8f05cb04cf445--

모든 메시지가 다릅니다.

스트리핑 된 코드는 다음과 같습니다

require('class.phpmailer.php'); 
require('fpdf.php'); 
define('FPDF_FONTPATH','font/'); 

//Create new PDF 
$pdf=new PDF(); 
$pdf->AliasNbPages(); 
$pdf->company = $business; 

$pdf->SetFont('Arial','',12); 
$pdf->SetAutoPageBreak(false); 
$pdf->AddPage('P'); 

// email stuff 
$tijd = time(); 
$datum = date('j-m-Y', $tijd); 
$bestandsnaam = $usernameinlog."-".$datum; 
$from = "[email protected]".$website; 
$subject = "Voorraad mutatie door ".$usernameinlog; 
$message = "<p>Zie bijlage voor een mutatieoverzicht.</p>"; 

// a random hash will be necessary to send mixed content 
$separator = md5(time()); 

// carriage return type (we use a PHP end of line constant) 
$eol = PHP_EOL; 

// attachment name 
$filename = $bestandsnaam.".pdf"; 

// encode data (puts attachment in proper format) 
$pdfdoc = $pdf->Output("", "S"); 
$attachment = chunk_split(base64_encode($pdfdoc)); 

// main header (multipart mandatory) 
$headers = "From: ".$from.$eol; 
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol; 
$headers .= "Content-Transfer-Encoding: 7bit".$eol; 
$headers .= "This is a MIME encoded message.".$eol.$eol; 


// The actual message 
$headers .= "--".$separator.$eol; 
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol; 
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol; 
$headers .= $message.$eol.$eol; 

// Bijlage 
$headers .= "--".$separator.$eol; 
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
$headers .= "Content-Transfer-Encoding: base64".$eol; 
$headers .= "Content-Disposition: attachment".$eol.$eol; 
$headers .= $attachment.$eol.$eol; 
$headers .= "--".$separator."--"; 


mail($emailemployee, $subject, "", $headers); 

사람이 잘못 가고 나는 php.ini 파일에 매개 변수를 놓친 거지 무엇을 알고 있나요? 다시 한번 :이 동일한 코드가 다른 서버에서 작동했기 때문에 일부 설정이 잘못되었거나 무언가를 설치하는 것을 잊어 버렸습니다.

:-) 감사,

알렉스

+0

그것은 모양 일부 해시 값처럼 - 코드를 게시 할 수 있습니까? PDF 생성 또는 전자 메일 전송 스 니펫과 유사합니다. – maialithar

+0

설명을 위해 위의 코드를 추가했습니다! –

답변

0

$eol = PHP_EOL;는 서버가 Windows를 실행하지 않는 경우 문제가 발생할 가능성이 높습니다.

이메일의 각 행 그래서 당신이해야, OS에 관계없이, CRLF로 끝나야합니다 하드 코드 때때로 $eol = "\r\n";

, 서버와 클라이언트는 CR 또는 LF 중 하나에 대응하지만, 그것은 비표준 그리고 그들이 정말 할 필요가 없다.

. 여전히이 후 문제가있는 경우


, 당신은 (아마도 2 개 라인에베이스 64 비트를 트림, 간결) 질문에 메시지 소스를 추가 할 수 있습니다하십시오? 당신은 기본적으로 어떻게 든 $ 헤더에 박제 전체 내용으로 빈 메시지를 전송

+0

메시지 소스는 정말 긴 코드이지만 Linux 서버에서 작동합니다. base64 비트를 2 줄로 자르는 것은 무엇을 의미합니까? Alex –

+0

@AlexvanRijs 소스가 긴 주된 이유는 그것이 첨부 파일을 포함하고 있다는 것입니다 (첨부 파일은 긴 base64로 인코딩 된 문자열로 전자 메일에 나타납니다) 그것은'AAAQAgAIAAAAQAAAAAAAAAIQAwAAAAAABAAAAAAAAABAQAwABAAAAAQAAABEQCgABAAAA'처럼 보이는 많은 줄입니다. 도움을 받으려면이 소스를 실제로 볼 필요가 있습니다 (그러나 모든 첨부 파일을 볼 필요가 없으므로 소스에서 base64 행을 제외하고 모두 제거 할 수 있습니다). 이 질문에 소스를 게시하거나 다른 곳에 게시하고 링크 할 수 있습니다. – SimonMayer

0
mail($emailemployee, $subject, "", $headers); 

....

대신에 $ 헤더의 $ 바디 변수에 $headers .= "Content-Transfer-Encoding: 7bit".$eol; 아래 최선을 다하는 시도하고

로 보내
mail($emailemployee, $subject, $body, $headers); 

(SimonMayer에 의해 제안도 $eol = "\r\n"$eol = PHP_EOL 교체)

+0

Gryphius, 나는 $ eol 변수를 "r \ n"으로 변경하여 코드를 업데이트하기 전에 제안했습니다.$ header를 $ body로 변경하고이 변수를 메일 기능에 추가하면 전자 메일을 보내지 않습니다. 반대쪽에서 $ header에두고 $ eol = "\ r \ n"을 남겨두면; 나는 메시지를 얻지 만, 여전히 해쉬 (- 41e12eb8038d06a471d8a74519f62fe5--) –

관련 문제