1

I am trying to send my message content as pdf format to the user through email. I used email functionality as phpmailer and dompdf. I don't know where I was mistaken. I didn't get the mail.it showing the error as no email id received.

here is my code:

<html>
<head>
    <title>Email Support</title>
</head>
<body>

    <?php
 require_once 'dompdf/autoload.inc.php';

    use Dompdf\Dompdf;

  $dompdf = new Dompdf();
    require_once('PHPMailer-master/class.phpmailer.php');

    $mail = new PHPMailer(true);

    $mail->IsSMTP();

    try {
        if (isset($_POST['message'])) {
            $message = $_POST['message'];
        } else {
            $message = "";
        }
        if (isset($_POST['emailid'])) {
            $emailid = $_POST['emailid'];

            $mail->Host = "";
            $mail->SMTPDebug = 0;
            $mail->SMTPAuth = true;
            $mail->Host = "";
            $mail->Port =;
            $mail->Username = "";
            $mail->Password = "";
            $mail->AddReplyTo('', '');
            $mail->AddAddress($emailid, ' ');
            $mail->SetFrom('', '');
            $mail->AddReplyTo('', '');
            $mail->Subject = "";
            $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
            $mail->MsgHTML($message);

            $dompdf = new Dompdf();
            $dompdf->loadHtml($message);
            $dompdf->render();
            $output = $dompdf->output();

            $mail->Send();
            echo "Message Sent OK</p>\n";
        } else {
            echo "No email id received.";
        }
    } catch (phpmailerException $e) {
        echo $e->errorMessage();
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    ?>

</body>

Can anyone help me?

Thanks in advance.

  • 1
    I'm guessing that all the empty strings in the PHPMail-setup are retracted values (removed for SO's sake)? – M. Eriksson Jul 18 '17 at 08:59
  • yes..i have that values..i just removed for safety purpose –  Jul 18 '17 at 09:00
  • You're creating a PDF, but you're not doing anything with it? Btw, set `$mail->SMTPDebug = 1;` while you're developing so you'll see what's actually going on. Do you get any exception? – M. Eriksson Jul 18 '17 at 09:02
  • it showing the error message as no email id received –  Jul 18 '17 at 09:03
  • Please share the error message (page it into your post). It's important that you add _all_ information in the question. – M. Eriksson Jul 18 '17 at 09:05
  • i have my SMTP details details in my file?here i just removed the details.. –  Jul 18 '17 at 09:05
  • ok i will add it in my post..can you please explain me how should i get the message content in pdf format.. –  Jul 18 '17 at 09:06
  • This is for adding the PDF as an attachement: https://stackoverflow.com/questions/11164167/phpmailer-attachment-doing-it-without-a-physical-file. - You should start by making the mail work without it first, though. – M. Eriksson Jul 18 '17 at 09:08
  • mail is working fine..i already tested it –  Jul 18 '17 at 09:09
  • How is _"I didn't get the mail.it showing the error as no email id received."_ the same as "working fine"? – M. Eriksson Jul 18 '17 at 09:12
  • no if i add dompdf code it showing like this..orelse its working fine..actually i dont have html page code i have only php code.. –  Jul 18 '17 at 09:12
  • `$mail->SMTPDebug = 1;` is not much use for diagnosing SMTP problems as it doesn't show you server messages; you need `$mail->SMTPDebug = 2;`. This is two separate problems: make a PDF, send an email - get them working independently before trying to do both. I can also tell you're using an old, obsolete, vulnerable version of PHPMailer, so make sure you [get the latest](https://github.com/PHPMailer/PHPMailer). – Synchro Jul 18 '17 at 09:14
  • is there any reference link for pdf format? –  Jul 18 '17 at 09:18

0 Answers0