In WordPress project I am using mPDF to generate pdf and send it as attachment via Mandrill. The only problem is Images aren't showing in pdf rather a square box with red cross is showing. But it works perfectly fine in localhost. Code:
$html = create_html($quote);
function create_html($quote = NULL) {
$logo = get_field( 'logo', 'option' );
$image = get_field( 'image', 'option' );
$title = get_field( 'title', 'option' );
$sub_title = get_field( 'sub_title', 'option' );
$content_image = get_field( 'content_image', 'option' );
$content = get_field( 'content', 'option' );
$html = '<!DOCTYPE html><html>';
$html .= '<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
$html .= '<style>
body {
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
font-size14px;
line-height:1.5;
font-weight: normal;
}
.container {
max-width: 690px;
margin: 0 auto;
}
figure{
padding:0;
}
.mailContent {
float: left;
width: 100%;
}
.top-mail.centerAlign {
padding-top: 30px;
padding-bottom: 20px;
float: left;
width: 100%;
}
.mid-mail.centerAlign {
padding-top: 20px;
padding-bottom: 10px;
float: left;
width: 100%;
}
figure.mail-fig {
padding-bottom: 20px;
float: left;
width: 100%;
}
.mailContent h1 {
color:#4A5467;
font-size: 85px;
padding-top: 20px;
padding-bottom: 30px;
float: left;
width: 100%;
font-weight: normal;
font-family: "CycloneBackground";
}
.mailContent .highlight-text {
padding-bottom: 30px;
max-width: 650px;
margin: 0 auto;
font-size: 22px;
line-height: 1.5;
}
.bot-mail {
border-top: 1px solid #eee;
// margin-top: 10px;
padding-top: 40px;
padding-bottom: 50px;
float: left;
width: 100%;
}
.blue-logo{
margin-right: 80px;
}
.bot-mail p, .top-mail-text p{
font-size: 16px;
overflow: hidden;
}
.wrapper690, .wrapper400{
max-width: 690px;
margin: 0 auto;
}
.wrapper400{
max-width: 400px;
}
img.db-comma {
padding-top: 10px;
padding-bottom: 12px;
}
.mailContent2 .top-mail.centerAlign {
padding-bottom: 30px;
}
.centerAlign{
text-align: center;
}
.fLeft{
float:left;
}
</style>';
$html .= '</head>';
$html .= '<body>';
$html .= '<div class="container"><div class="row"><div class="col-sm-12">';
if(!empty($quote)) {
$html .= '<div class="mailContent wrapper690 mailContent2">';
$html .= '<div class="top-mail centerAlign">';
$html .= '<img src="'.$logo.'" alt="" class="fLeft">';
$html .= '<div class="wrapper400 fRight top-mail-text">';
$html .= '<img src="'.get_stylesheet_directory_uri().'/assets/images/db-comma.PNG" alt="double comma" class="db-comma">';
$html .= $quote;
$html .= '</div>';
$html .= '</div>';
} else {
$html .= '<div class="mailContent wrapper690">';
$html .= '<div class="top-mail centerAlign"><img src="'.$logo.'" alt=""></div>';
}
$html .= '<div class="mid-mail centerAlign">';
$html .= '<figure class="mail-fig"><img src="'.$image.'" alt=" group"></figure>';
if(!empty($title)) {
// $html .= '<h1>'.$title.'</h1>';
$html .= '<h1>test</h1>';
}
if(!empty($sub_title)) {
$html .= '<p class="highlight-text">'.$sub_title.'</p>';
}
$html .= '</div>';
$html .= '<div class="bot-mail">';
if(!empty($content_image)) {
$html .= '<img src="'.$content_image.'" alt=" logo blue" class="fLeft blue-logo">';
}
if(!empty($content)) {
$html .= $content;
}
$html .= '</div>';
$html .= '</div>';
$html .= '</div></div></div>';
$html .= '</body>';
$html .= '</html>';
return $html;
}
$mpdf = new mPDF();
$mpdf->SetDisplayMode('real');
$html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
$mpdf->WriteHTML($html);
ob_clean();
$path_certificate = ABSPATH."certificates/";
$certificate_filename = 'Gåvobevis_'.$_SESSION['first_name'].'_'.$_SESSION['last_name'].'_'.uniqid();
$certificate_filename = $certificate_filename.'.pdf';
$mpdf->Output($path_certificate.$certificate_filename, 'F');
mail sending:
$attachment = file_get_contents($path_certificate.$certificate_filename);
$attachment_encoded = base64_encode($attachment);
$params = array(
'html' => $message,
"text" => null,
"from_email" => $from,
"from_name" => "Admin",
"subject" => $subject,
"to" =>array(array('email' => $to )),
"track_opens" => true,
"track_clicks" => true,
"auto_text" => true,
"attachments" => array(
array(
'content' => $attachment_encoded,
'type' => "application/pdf",
'name' => $certificate_filename,
)
)
);
I am getting image from admin as custom option. Image url is coming as : http://xxx.xx.x.xxx/projectname/wp-content/uploads/2017/08/e-img1.png Any help/suggestions are welcome. Thanks in advance.