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

我创建了一个成功创建的动态pdf使用fpdf。 此代码是完美的工作在我的第一次托管,但是当我在另一个域上使用,那么这不是只发送显示消息发送。 我使用电子邮件标题中的无回复。使用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

好吧,我会检查我的服务器的PHP版本 –

+0

代码工作在PHP版本5.4.38和不工作在PHP版本5.3 –

相关问题