2017-07-21 3 views
0

J'ai configuré le système où, en cliquant sur le bouton, le contrat est envoyé avec le fichier pdf ci-joint. J'ai utilisé mpdf pour envoyer l'e-mail à l'adresse e-mail requise. Le code suivant fonctionne correctement sur mon hôte local et fait le travail correctement, mais quand je le mets sur le serveur, il ne montre aucune erreur mais aussi n'envoie aucun email comme je ne reçois rien. Pouvez-vous m'aider à comprendre ce que je fais peut-être mal?Envoi d'un e-mail PDF avec MPDF

// Setup PDF 
    $mpdf = new mPDF('utf-8', 'Letter', 0, '', 0, 0, 0, 0, 0, 0); // New PDF object with encoding & page size 
    ob_start(); 
    $mpdf->setAutoTopMargin = 'stretch'; // Set pdf top margin to stretch to avoid content overlapping 
    $mpdf->setAutoBottomMargin = 'stretch'; // Set pdf bottom margin to stretch to avoid content overlapping 
    $mpdf->WriteHTML($stylesheet,1); // Writing style to pdf 
    $mpdf->WriteHTML($html); // Writing html to pdf 
    // FOR EMAIL 
    $content = $mpdf->Output('', 'S'); // Saving pdf to attach to email 
    $content = chunk_split(base64_encode($content)); 
    $emailto = '[email protected]'; 
    //The function to send email when the contract is requested 
    $recepients = array(
     $email, 
     '[email protected]' 
    ); 
    $mailto = implode(',', $recepients); 
    $from_name = 'Random Project'; 
    $from_mail = '[email protected]'; 
    $replyto = '[email protected]'; 
    $uid = md5(uniqid(time())); 
    $subject = 'Wedding Contract Form'; 
    $message = ' 
     </<!DOCTYPE html> 
     <html> 
     </style> 
     <body> 
     <img src="http://tanglewoodestate.com.au/assets/contract-header.png" width="400px"> 
     <div width ="300px" style="background-color:#f5e9dd;padding:10px"> 
     <p>Hi <strong>'.$cname.'</strong>,<p> 
     <p>Please Find the <strong>attached contract</strong> from the Tanglewood Estate.</p> 
     <p>For any questions or queries,Please contact Us at:<br> 
     ABC<br> 
     [email protected]<br> 
     </div> 
     <img src="http://tanglewoodestate.com.au/assets/contract-footer.png" width="400px"> 
     </body> 
     </html>'; 
    $filename = 'Wedding_contract.pdf'; 
    $header = "From: ".$from_name." <".$from_mail.">\r\n"; 
    $header .= "Reply-To: ".$replyto."\r\n"; 
    $header .= "MIME-Version: 1.0\r\n"; 
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; 
    $header .= "This is a multi-part message in MIME format.\r\n"; 
    $header .= "--".$uid."\r\n"; 
    $header .= "Content-type:text/html;charset=UTF-8\r\n"; 
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; 
    $header .= $message."\r\n\r\n"; 
    $header .= "--".$uid."\r\n"; 
    $header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n"; 
    $header .= "Content-Transfer-Encoding: base64\r\n"; 
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; 
    $header .= $content."\r\n\r\n"; 
    $header .= "--".$uid."--"; 
    $is_sent = @mail($mailto, $subject, "", $header); 
    //$mpdf->Output(); // For sending Output to browser 

    //$mpdf->Output('Wedding_contract.pdf','D'); // For Download 
    ob_end_flush(); 
    } 
+0

ne pas envoyer et ne pas recevoir ne sont pas la même chose – rtfm

+0

votre bien mieux d'utiliser l'une des bibliothèques de publipostage standard telles que phpmailer que le courrier() – rtfm

+0

rtfms - Seulement si vous pouvez comprendre que pour les tests, je m'envoie ça. –

Répondre

0

La réponse est tiré du fil: mPDF Auto Generated PDF Mailer sends blank Email par https://stackoverflow.com/users/3818025/drehx

Alors, je viens d'utiliser PHP Mailer pour envoyer l'e-mail. affichage Juste ce pour aider tous ceux qui voudraient l'utiliser comme exemple:

try { 

$mail = new PHPMailer; 
$mail->AddAddress($email); 
$mail->AddAddress('[email protected]'); 
$mail->AddAddress('[email protected]'); 
$mail->SetFrom('[email protected]'); 
$mail->AddReplyTo('[email protected]'); 
$mail->Subject = 'Tanglewood Contract'; 
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically 
$mail->isHTML(true); 
$mail->Body = '</<!DOCTYPE html> 
    <html> 
    </style> 
    <body> 
    <img src="http://tanglewoodestate.com.au/assets/contract-header.png" width="400px"> 
    <div width ="300px" style="background-color:#f5e9dd;padding:10px"> 
    <p>Hi <strong>'.$cname.'</strong>,<p> 
    <p>Please Find the <strong>attached contract</strong> from the Tanglewood Estate.</p> 
    <p>For any questions or queries,Please contact Us at:<br> 
    Tanglewood Estate<br> 
    [email protected]<br> 
    </div> 
    <img src="http://tanglewoodestate.com.au/assets/contract-footer.png" width="400px"> 
    </body> 
    </html>'; 

//$mail->MsgHTML("*** Form attached! Please see the attached form (.pdf)."); 
$mail->AddStringAttachment($content, $filename = 'TanglewoodContract.pdf', 
     $encoding = 'base64', 
     $type = 'application/pdf');  // attachment 
if (isset($_FILES['attached']) && 
    $_FILES['attached']['error'] == UPLOAD_ERR_OK) { 
    $mail->AddAttachment($_FILES['attached']['tmp_name'], 
         $_FILES['attached']['name']); 
} 
$mail->Send(); 
echo "<div style='margin-left:4%;'>Message Sent OK</div>\n"; 
} catch (phpmailerException $e) { 
echo $e->errorMessage(); //Pretty error messages from PHPMailer 
} catch (Exception $e) { 
echo $e->getMessage(); //Boring error messages from anything else! 
}