2016-03-29 17 views
0

PHPMailer aracılığıyla gönderilecek ekleri göremiyorum. İşte e-posta göndermek için kodu için ne var:PHPMailer & Dompdf Ek Sorunları

REVİZE AutoMailer İçerik:

if(isset($_POST['type']) && $_POST['type'] == 'sendEmail'){ 
    require_once 'phpMail/PHPMailerAutoload.php'; 
    $email = $_POST['email']; 
    $uuid = $_POST['uuid']; 
    $file_content = file_get_contents(BASE_PATH.'email.php?uuid='.$uuid); 
    $pdf_content = file_get_contents(BASE_PATH.'pdf.php?uuid='.$uuid); 
    $mail = new PHPMailer; 
    $mail->From = ADMIN_EMAIL; 
    $mail->FromName = SENDER_NAME; 
    $mail->addAddress($email);    // Name is optional 
    $mail->addReplyTo(REPLY_EMAIL, 'Reply Mail'); 
    $mail->isHTML(true);         // Set email format to HTML 
    $mail->Subject = 'Email From '.User; 
    $mail->Body = $file_content; 
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 
    $mail->AddStringAttachment($output, attach.pdf); 
    if(!$mail->send()) { 
     echo 'Message could not be sent.'; 
     echo 'Mailer Error: ' . $mail->ErrorInfo; 
    } else { 
     echo "true"; 
    } 

    exit; 
} 

REVİZE DOMPDF Kodu (pdf.php)

$html .= //Content Here 
$dompdf = new DOMPDF(); 
$dompdf->load_html($html); 
$dompdf->render(); 
$canvas = $dompdf->get_canvas(); 
$canvas->page_script(' 
    if ($PAGE_NUM > 1) { 
    $font = Font_Metrics::get_font("helvetica", "bold"); 
    $current_page = $PAGE_NUM-1; 
    $total_pages = $PAGE_COUNT-1; 
    $pdf->text(522, 770, "Page: $current_page of $total_pages", $font, 10, array(0,0,0)); 
    } 
'); 
$output = $dompdf->output(); 
file_put_contents('Attachment.pdf', $output); 

ben ilgilendiren kodu kaldırırsanız eki, e-posta sadece ince (vücutta email.php ile) gönderir. Ekler, ancak ... çalışmak

+0

Peki göndermeden önce sunucuya dosya kurtardı phpmailer ile? – Naruto

+0

@Naruto Her şeyden önce, serin isim; D. İkincisi, istemediğim takdirde dosyayı sunucuya kaydetmek istemedim, eğer zorundaysam, sadece geçici bir dosyaya kaydetmek istiyorum, Üçüncü olarak, PHPAutoMailer için oldukça yeni ve emin değilim Bunun nasıl yapılacağı: D En iyi yorum, sunucuya kaydetmek zorunda kalsam bile en iyi uygulama ne olursa olsun giderdim. – Steven

+0

'$ dompdf-> stream()' yöntemi, kullanıcı tarayıcıda bir indirme iletişim kutusunu açmak için kullanılır. Yani ek için kullanamazsın. Aşağıdaki Naruto yöntemini kullanın. – ThinkTank

cevap

0

Çalışma Kodu reddetme:

Sunucu Kodu:

if(isset($_POST['type']) && $_POST['type'] == 'sendEmail'){ 
    require_once 'phpMail/PHPMailerAutoload.php'; 
    $email = $_POST['email']; 
    $uuid = $_POST['uuid']; 
    $file_content = file_get_contents(BASE_PATH.'email.php?uuid='.$uuid); 
    $pdf_content = file_get_contents(BASE_PATH.'pdfemail.php?uuid='.$uuid); 
    $mail = new PHPMailer; 
    $mail->From = ADMIN_EMAIL; 
    $mail->FromName = SENDER_NAME; 
    $mail->addAddress($email);    // Name is optional 
    $mail->addReplyTo(REPLY_EMAIL, 'Reply Mail'); 
    $mail->isHTML(true);         // Set email format to HTML 
    $mail->Subject = 'Project From '.COMPANY_NAME; 
    $mail->Body = $file_content; 
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 
    $mail->AddAttachment('./attachments/attach.pdf', "Attachment.pdf"); 
    if(!$mail->send()) { 
     echo 'Message could not be sent.'; 
     echo 'Mailer Error: ' . $mail->ErrorInfo; 
    } else { 
     echo "true"; 
    } 

    exit; 
} 

DOMPDF Dosya:

$dompdf = new DOMPDF(); 
$dompdf->load_html($html); 
$dompdf->render(); 
$canvas = $dompdf->get_canvas(); 
$canvas->page_script(' 
    if ($PAGE_NUM > 1) { 
    $font = Font_Metrics::get_font("helvetica", "bold"); 
    $current_page = $PAGE_NUM-1; 
    $total_pages = $PAGE_COUNT-1; 
    $pdf->text(522, 770, "Page: $current_page of $total_pages", $font, 10, array(0,0,0)); 
    } 
'); 
$output = $dompdf->output(); 
$file_to_save = './attachments/attach.pdf'; 
file_put_contents($file_to_save, $output);