0

I'm trying to send email with a QR image in my PHP plugin. First I generate the qr image and save it in a new folder with a custom name.

$PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'qr'.DIRECTORY_SEPARATOR;
$PNG_WEB_DIR = 'qr/';
include "phpqrcode/qrlib.php";
if (!file_exists($PNG_TEMP_DIR))
   mkdir($PNG_TEMP_DIR);
$filename = $PNG_TEMP_DIR.'qr_' . $post_id . '_' . $num_ref . '.png';
$qr_content = '
              Evento: ' . $event_title . '</br>
              Nº de referencia: ' . $num_ref . '
';

QRcode::png($qr_content, $filename, QR_ECLEVEL_L, 5);

Then I have to send an email with some information and the QR image inside. I try with this:

$subject = $event_title . ' Confirmation';
$headers .= "From: WrocLoveLive" . "\r\n";
$message = '
  <html>
    <head></head>
    <body>
      <p>Enhorabuena ! Te has inscrito en el evento: ' . $event_title . ' el cual será el día ' . $event_date_ini . '</p>
      <p>Tu número de referencia es: ' . $num_ref . '</p>
      <p>Si deseas ver la información el evento, por favor, visita el siguiente enlace: </p>
      <a href="' . $event_url . '">' . $event_url . '</a>
      <p>Para acceder al evento se requerirá mostrar el siguiente código QR:</p>
      <img src="http://localhost:8888/wroclovelive/wp-content/plugins/ceventmanager/admin/qr/qr_' . $post_id . '_' . $num_ref . '" alt="" />
      <p>Esto es un mensaje automático, por favor no conteste</p>
    </body>
  </html>
  ';
$mail_confirm = mail($user_mail, $subject, $message, $headers);
if ($mail_confirm == true) {?>
   <div class="message-pers"">
      <p>Enhorabuena !! Te has suscrito correctamente en el evento</p>
   </div>
<?php
}

The email is send correctly, but I can't view the image. The email is like that:

Email

Is there someone who can help me?

Thank you so much !

  • An email will load any external resource from the domain you are giving it. If you add images with localhost as the domain, they will never show up as localhost is the host machine. Please put your images on an accessible public server and update the url to those, not localhost. – Ovidiu Jun 11 '18 at 17:24
  • @Ovidash Okey ! but...do you know how can I do this? I mean, how can I save the image in external server? – Josemi Calvo Jun 11 '18 at 17:28
  • What do you mean man? On the actual server where you will host your website when you finish it. Or better yet, get a development server and code on it. But never ever use localhost urls for external testing. The localhost url will only work on your machine locally, and not for an email service to fetch data from your machine – Ovidiu Jun 11 '18 at 17:36
  • Hi, you need to embed the picture then call it with the cid. See this https://stackoverflow.com/questions/6095285/how-can-i-attach-an-image-using-phpmailer – Flyzzx Jun 11 '18 at 17:39
  • Yes yes I know what you mean @Ovidash but this is a university task and I don't have to upload the web to a server, I only work on localhost. And I don't know how can i use an external server only to save the images and to get them. – Josemi Calvo Jun 11 '18 at 17:41
  • try to use an image api to upload the image there and get the URL back for you to use. imgur.com has quite an easy api to work with and can keep the images private if needed. – Ovidiu Jun 11 '18 at 17:44

0 Answers0