2017-05-06 9 views
0
This is my code for sending an email with dynamic generated pdf using fpdf in php. 

필자는 성공적으로 생성 된 동적 pdf use fpdf를 만듭니다. 이 코드는 첫 번째 호스팅에서 완벽하게 작동하지만 다른 도메인에서 사용할 때 메시지 보내기 만 보내는 것이 아닙니다. 전자 메일 헤더에 no-reply를 사용합니다.fpdf를 사용하여 php에서 attachemnt로 이메일 보내기?

if (isset($_POST['submit'])) { 
     $payment = $_POST['payment']; 
     if ($errorMsg == "") { 
      require("fpdf181/fpdf.php"); 
      $pdf  = new FPDF(); 
      $pdf -> AddPage(); 
      $pdf -> SetFont('Arial', 'B', 16); 
      $pdf -> SetFont('Arial', 'B', 16); 
      $pdf -> Image('images/logo.png', 95, 15, 20, 0); 
      $pdf -> SetFontSize(10); 
      $pdf -> SetTextColor(30, 30, 100); 
      $pdf -> SetFont('Arial', 'B', 15); 
      $pdf -> Line(10, 51, 200, 51); 
      $pdf -> SetFontSize(10); 
      $pdf -> SetTextColor(30, 30, 100); 
      $pdf -> SetFont('Arial', 'B', 15); 
      $pdf -> Line(10, 247, 200, 247); 
      $pdf -> SetXY(88, 37); 
      $pdf -> SetFontSize(17); 
      $pdf -> SetTextColor(0, 0, 0); 
      $pdf -> Write(7, 'Website'); 
      $pdf -> SetXY(75, 10); 
      $pdf -> SetDrawColor(50, 60, 100); 
      $pdf -> SetXY(90, 55); 
      $pdf -> SetFontSize(13); 
      $pdf -> SetTextColor(0, 0, 0); 
      $pdf -> Write(7, 'Order Information'); 
      $pdf -> SetFontSize(11); 
      $pdf -> SetXY(10, 65); 
      $pdf -> Write(7, 'Order Details'); 
      $pdf -> SetXY(10, 75); 
      $pdf -> Write(7, 'Order ID : '); 
      $pdf -> SetXY(50, 75); 
      $pdf -> Write(7, '#12121920120'); 
      $pdf -> SetXY(10, 82); 
      $pdf -> Write(7, 'Date Added : '); 
      $pdf -> SetXY(50, 82); 
      $pdf -> Write(7, '11/12/2017'); 
      $pdf -> SetXY(10, 89); 
      $pdf -> Write(7, 'Payment Method : '); 
      $pdf -> SetXY(50, 89); 
      $pdf -> Write(7, 'Direct Transfer'); 
      $pdf -> SetXY(10, 120); 
      $pdf -> Write(7, 'Billing Address'); 
      $pdf -> SetXY(10, 130); 
      $pdf -> Write(7, 'Name : '); 
      $pdf -> SetXY(50, 130); 
      $pdf -> Write(7, 'ABC'); 
      $pdf -> SetXY(10, 137); 
      $pdf -> Write(7, 'Address : '); 
      $pdf -> SetXY(50, 137); 
      $pdf -> Write(7, 'Hisar'); 
      $pdf -> SetXY(10, 144); 
      $pdf -> Write(7, 'City : '); 
      $pdf -> SetXY(50, 144); 
      $pdf -> Write(7, 'Hisar city'); 
      $pdf -> SetXY(10, 159); 
      $pdf -> Write(7, 'Amount Payable : '); 
      $pdf -> SetXY(50, 159); 
      $pdf -> Write(7, '$5587'); 
      $pdf -> SetXY(10, 175); 
      $pdf -> Write(7, 'Display Location '); 
      $pdf -> SetXY(10, 185); 
      $pdf -> Write(7, 'city'); 
      $pdf -> SetXY(50, 185); 
      $pdf -> Write(7, 'City_name'); 
      $pdf -> SetXY(10, 192); 
      $pdf -> Write(7, 'Location'); 
      $pdf -> SetXY(50, 192); 
      $pdf -> Write(7, 'Locality'); 
      $pdf -> SetFontSize(20); 
      $pdf -> SetTextColor(0, 0, 0); 
      $pdf -> SetXY(50, 250); 
      $pdf -> Write(7, 'Thank You For Choosing Us'); 
      $pdf -> SetFontSize(12); 
      $pdf -> SetTextColor(0, 0, 0); 
      $pdf -> SetXY(10, 260); 
      $pdf -> Write(7, 'Contact Email : [email protected]'); 
      $pdf -> SetXY(132, 260); 
      $pdf -> Write(7, 'Mobile No. : +91-1201210921'); 
      $pdf -> Ln(); 
      $to   = '[email protected]'; 
      $from  = "[email protected]"; 
      $message = "Test email with attachment"; 
// 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 = 'Test.pdf'; 
// encode data (puts attachment in proper format) 
      $pdfdoc  = $pdf -> Output("", "S"); 
      $attachment = chunk_split(base64_encode($pdfdoc)); 
// main header 
      $headers = "From: Website <" . $from . ">" . $eol; 
// 
      $headers .= "MIME-Version: 1.0" . $eol; 
      $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\""; 
// $headers = "MIME-Version: 1.0" . "\r\n"; 
// $headers.="Content-type:text/html;charset=UTF-8" . "\r\n"; 
// no more headers after this, we start the body! // 
      $body  = "--" . $separator . $eol; 
      $body  .= "Content-Transfer-Encoding: 7bit" . $eol . $eol; 
      $body  .= "" . $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 
      $okk  = mail($to, $subject, $body, $headers); 
      if ($okk) { 
      echo "send"; 
      if ($payment == 'Direct Bank Transfer' || $payment == 'Cheque Payment') { 
//   echo '<script type="text/javascript">alert("' . $order2 . '");</script>'; 
       echo "<script type='text/javascript'>window.location.assign('index.php?session_id=$order_session');</script>"; 
      } 
      else { 
       echo "<script type='text/javascript'>window.location.assign('index.php');</script>"; 
      } 
      } 
      else { 
      echo "fail"; 
      } 
     } 
    } 

이 코드는 새로운 등록을 위해 사용 중입니다.

$to_ad = "[email protected]"; 
    $subject_ad = "One New User Registered"; 
    $message_ad = "Name : $name<br /><br/>E-mail : $email<br/><br />Password : $password<br />"; 
    $to2 = $email; 
    $subject = "Welcome to Website"; 
    $message = 'Thank you for joining us.<br/><br />Name : ' . $name . '<br /><br/>E-mail : ' . $email . '<br /><br/>Password : ' . $password . '<br /><br /> 
    <strong style="font-size:18px;"><a target="_blank" href="http://domain.in/email=' . $email . '&hash=' . $hash . '">Click here to email verification</a></strong>'; 
    $headers = "MIME-Version: 1.0" . "\r\n"; 
    $headers.="Content-type:text/html;charset=UTF-8" . "\r\n"; 
    $headers .= 'From: Website <[email protected]>' . "\r\n"; 
    mail($to_ad, $subject_ad, $message_ad, $headers); 
    mail($to2, $subject, $message, $headers); 

어떻게 고칠 수 있습니까?

+0

문제는 서버 관련 일 수 있습니다. –

+0

아니요 ...... 내 새 등록 코드가 동일한 서버에서 작동하고 있습니다. –

+0

새 서버 메일, DNS 설정 등을 확인하십시오. –

답변

0

동일한 도메인을 사용하여 전자 메일을 보내고받는 경우 작동하지 않을 수 있습니다. from 헤더를 새 도메인으로 변경하려고합니다. 그리고 마지막 원인은 코드 및 PHP 버전과 호환되지 않을 수 있습니다 (다른 호스팅을 사용하는 경우).

+0

알겠습니다. 서버 버전을 확인해 보겠습니다. –

+0

코드는 PHP 5.4.38에서 작동하며 PHP 5.3에서는 작동하지 않습니다. –