2013-03-21 3 views
1

PHP로 메일을 보내면 Gmail에는 올바르게 표시되지만 Outlook에는 표시되지 않습니다. PDF 첨부 파일과 일부 텍스트가 포함 된 메일입니다. PDF는 fpdf로 만들어 첨부 파일로 보내지 만 Gmail과 Outlook에서 제대로 작동합니다.PHP 메일이 Gmail에서는 열리지 만 Outlook에서는 열리지 않습니다.

유일한 문제는 Gmail에서 이메일의 텍스트가 올바르게 표시되고 Outlook에서는 빈 페이지이며 텍스트가 추가 첨부 파일이라는 것입니다.

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

// email stuff (change data below) 
$to = $contactEmail; 
$from = $myEmail; 
$subject = "MySubjectHere"; 
$message = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
      "http://www.w3.org/TR/html4/loose.dtd"> 
      <html><head></head><body> 
      <p>Hi '$contactName.',</p><br> 
      <p>Please find your pdf attached per your request.</p> 
      <p>Feel free to call or email if you have any questions.</p> 
      <p>Kind regards,</p><br> 
      <p>MyNameHere</p> 
      <p><strong>Manager</strong></p> 
      <img alt="image" src="http://LinkToImage.png"/> 
      <p style="color:#76923c;"> 
      <strong>P:</strong> 01 2345 6789| 
      <strong>W:</strong> <a href="http://www.example.com" target="_blank">www.example.com</a></p> 
      <p style="color:#76923c;"> 
      <strong>A:</strong> 94 Test Street. 
      </p></body></html>'; 

// 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 = $id."_".str_replace(" ","_",$Name).'.pdf'; 

// main header 
$headers = "From: ".$from.$eol; 
$headers .= "Bcc: ".$from.$eol; 
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\""; 

// no more headers after this, we start the body! // 

$body = "--".$separator.$eol; 
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol; 

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

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

// send message 
mail($to, $subject, $body, $headers); 
+0

질문이 있습니다. php를 사용하여 Outlook으로 전자 메일을 보내고받을 수 있습니까? 고맙습니다. – User014019

+0

예. 헤더가 맞는지 확인하고 메시지 끝에 2 줄의 끝이 있어야합니다. 구조가 정확하다면 모든 클라이언트의 메일을 볼 수 있습니다. –

+0

어떻게? 나는 전망에 이메일을 보내려고하지만 아무 것도받지 못했다. SMTP 서버와 포트를 넣어야합니까? – User014019

답변

2

바로 첨부 파일을 필요가 없습니다 !
어쨌든 답변 해 주셔서 감사합니다!

0
$to = $contactEmail; 
$from = $myEmail; 
$boundary = md5(date('r', time())); 
$msg = "This is a multi-part message in MIME format.\n\n"; 
$msg .= "--$boundary\n"; 
$msg .= "Content-Type: text/html; charset=utf-8; format=flowed; delsp=yes\n"; 
$msg .= "Content-Transfer-Encoding: 7bit\n\n"; 
$msg .= "<h1>Website Enquiry</h1> 
      <p><strong>Name:</strong> $name<br /> 
      <strong>Email:</strong> $email<br /> 
      <strong>Phone:</strong> $phone<br /> 
      <strong>Subject Name:</strong> $subject<br /> 
      <strong>Question:</strong> $question</p>"; 

$e_headers = "From: " . $from . "\n"; 
$e_headers .= "MIME-Version: 1.0\n"; 
$e_headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n"; 

mail($to, $subject, $msg, $e_headers); 

이 나는 ​​HTML 문의 양식에 사용하는 것이 코드 :

여기 내 코드입니다. 마지막으로 삼일 후에 발견

$body .= $message.$eol; 

$body .= $message.$eol.$eol; 

해야합니다 당신은 PHP_EOL을 통해 내용을 전달하는 잘못 어디로 갔는지 내가 찾은

+0

감사하지만 작동하지 않습니다. 여전히 동일한 문제입니다. –

0
$separator = md5(time()); 
$eol = "\r\n"; 
$message=""; // Always empty 
$mailmessage="<h1>Yes got it</h1>"; //html content 

$headers = "From: ".$email.$eol; 
$headers .= "Bcc:". $Bcc. "\n"; 
$headers .= "Cc:". $cc. "\n"; 
$headers .= "Return-Path: <".$email.">\n"; 
$headers .= "MIME-Version: 1.0" . $eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol; 
$headers .= "Content-Transfer-Encoding: 7bit" . $eol; 

$body .= "--" . $separator . "\r\n"; 
$body .= "Content-type:text/plain; charset=iso-8859-1\r\n"; 
$body .= "Content-Transfer-Encoding: 7bit\r\n"; 
$body .= $message . "\r\n"; 

$body = "--" . $separator . $eol; 
$body .= "Content-type: text/html; charset=\"utf-8\"\r\n"; 
$body .= "Content-Transfer-Encoding: 8bit\r\n\r\n"; 
$body .= $mailmessage . $eol.$eol; 

$body .= "--" . $separator . $eol; 
$body .= "Content-Type: application/octet-stream; name=\"" . $file . "\"" . $eol; 
$body .= "Content-Transfer-Encoding: base64" . $eol.$eol; 
$body .= "Content-Disposition: attachment" . $eol; 
$body .= $content . $eol; 
$body .= "--" . $separator . "--"; 

mail($to, $subject, $body, $headers); 
관련 문제