WordPress

Podczas tworzenia niestandardowej wiadomości e-mail nie mogę wstawić więcej niż jednego obrazu

  • 14 kwietnia, 2024
  • 3 min read
Podczas tworzenia niestandardowej wiadomości e-mail nie mogę wstawić więcej niż jednego obrazu


Jeśli umieściłem tylko jeden obraz w kodzie HTML, wygląda on poprawnie, ale kiedy umieściłem drugi w tym przypadku recyclingimg.png wszystko się psuje

funkcja creacionQR($url, $emailDestinatario, $empresa, $nombre, $puesto){ $dir=”temp/”; if (!file_exists($dir) && !mkdir($dir, 0777, true)) { echo „Nie można utworzyć katalogu tymczasowego.”; zwróć fałsz; } $dirdos = $_SERWER[’DOCUMENT_ROOT’] . '/greencards/wp-content/themes/greencards/img/’;

$additionalImage = $dirdos . 'reciclajeimg.png';
if (!file_exists($additionalImage) || !is_readable($additionalImage)) {
    echo "El archivo adicional no existe o no se puede leer.";
    return false;
}
$attachmentAdditional = chunk_split(base64_encode(file_get_contents($additionalImage)));

$filename = $dir.'test.png';
$size = 10;
$level="H"; 
$frameSize = 3; 

QRcode::png($url, $filename, $level, $size, $frameSize);

$to = $emailDestinatario;
$subject = "Su tarjeta con codigo QR";
$separator = md5(time());
$eol = PHP_EOL;
$headers = "From: [email protected]" . $eol;
$headers .= "MIME-Version: 1.0" . $eol; 
$headers .= "Content-Type: multipart/related; boundary=\"" . $separator . "\"" . $eol;

$attachment = chunk_split(base64_encode(file_get_contents($filename)));

$body = "--" . $separator . $eol;
$body .= "Content-Type: text/html; charset=\"UTF-8\"" . $eol;
$body .= "Content-Transfer-Encoding: 7bit" . $eol;
$body .= $eol;
$body .= "<!DOCTYPE html><html><body>";
$body .= "<div style="width: 336px; height: 215px; border-radius: 20px; border: 1px solid black; margin: 10px 0px;">";
$body .= "<table style="width: 100%; height: 100%; border: 0;">";
$body .= "<tr><td style="text-align: center;"><h1 style="margin: 0;margin-top: 24px; font-size: 60px;">" . htmlspecialchars($empresa) . "</h1></td></tr>";
$body .= "<tr><td style="text-align: center;"><h1 style="margin: 0;">" . htmlspecialchars($nombre) . "</h1></td></tr>";
$body .= "<tr><td style="text-align: center;"><h3 style="margin: 0; margin-bottom: 20px;">" . htmlspecialchars($puesto) . "</h3></td></tr>";
$body .= "</table></div>";
$body .= "<table style="width: 336px; height: 215px; border-radius: 20px; border: 1px solid black;">";
$body .= "<tr><td style="text-align: center;"><img src=" style="width: 115px; height: 115px; margin-top: 10px;"></td></tr>";
$body .= "<tr><td style="text-align: center;"><img src="cid:reciclajeimg.png"></td></tr>";
$body .= "<tr><td style="text-align: center; margin: 0;"><h4 style="margin: 0;">Producto de GreenCards.es</h4></td></tr>";
$body .= "<tr><td style="text-align: center;"><h4 style="margin-bottom: 15px; margin-top: 4px;" >Has contribuido a plantar 1 árbol con esta tarjeta</h4></td></tr>";
$body .= "</table>";
$body .= "</body></html>" . $eol;

$body .= "--" . $separator . $eol;
$body .= "Content-Type: image/png; name=\"" . basename($additionalImage) . "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-ID: <reciclajeimg.png>" . $eol;
$body .= "Content-Disposition: inline; filename=\"" . basename($additionalImage) . "\"" . $eol;
$body .= $attachmentAdditional . $eol;

$body .= "--" . $separator . $eol;
$body .= "Content-Type: image/png; name=\"" . basename($filename) . "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-ID: <test.png>" . $eol;
$body .= "Content-Disposition: inline; filename=\"" . basename($filename) . "\"" . $eol;
$body .= $attachment . $eol;
$body .= "--" . $separator . "--";

if (wp_mail($to, $subject, $body, $headers)) {
    return true;
} else {
    return "Error al enviar el correo.";
}

}


Źródło

Warto przeczytać!  Błąd 404 Admin-ajax.php — WordPress Development Stack Exchange