Salve,
ho provato a fare in modo che tutte le mail che vengono mandate dal mio sito risultassero in un documento html con div e stili, come fanno in molti.
Il codice in questione sarebbe:Questa funzione, poi, verrebbe richiamata semplicemente in questo modo:Codice:$email_headers = "MIME-Version: 1.0" . "\r\n"; $email_headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $email_headers .= 'From: <seintian@altervista.org>' . "\r\n"; $pre_styles = " :root { --bg-color: rgb(10, 10, 10); --text-color: rgb(200, 200, 200); --fg-color: rgb(90, 25, 140); --darker-bg-color: rgb(30, 30, 30); --darkest-bg-color: rgb(20, 20, 20); --darker-text-color: rgb(170, 170, 170); --red-fg-color: rgb(200, 0, 0); --light-shadow: rgb(30, 30, 30); --topbar-height: 2rem; --optimal-article-width: 65ch; --card-border-width: 5px; --monospace-font-family: \"Consolas\", \"Andale Mono WT\", \"Andale Mono\", \"Lucida Console\", \"Lucida Sans Typewriter\", \"DejaVu Sans Mono\", \"Bitstream Vera Sans Mono\", \"Liberation Mono\", \"Nimbus Mono L\", \"Monaco\", \"Courier New\", Courier, monospace; font-size: 18px; } html, body { margin: 0; min-width: 100%; scroll-behavior: smooth; height: 100%; } * { box-sizing: content-box; } body { background-color: var(--bg-color); color: var(--text-color); font-family: Arial, Helvetica, sans-serif; word-break: break-word; } a { color: var(--text-color); transition: .2s; } a:hover { color: var(--fg-color); } a.no-link { text-decoration: none; } div#main { width: var(--optimal-article-width); margin: 2rem auto; } "; function sendMyMail($to, $subject, $body, $other_headers = "") { global $email_headers, $pre_styles; mail($to, $subject, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional //EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:v=\"urn:schemas-microsoft-com:vml\" lang=\"en\"> <head> <meta property=\"og:title\" content=\"$subject\"> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"> <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> <title>$subject</title> <link rel=\"stylesheet\" type=\"text/css\" hs-webfonts=\"true\" href=\"https://fonts.googleapis.com/css?family=Lato|Lato:i,b,bi\"> <style type=\"text/css\"> $pre_styles </style> </head> <body>" . $body . "</body></html>", $email_headers . $other_headers); } ?>Purtroppo, però, le mail arrivano col testo normale, senza alcuna formattazione, sia su Gmail che su altri servizi simili.Codice:sendMyMail($email, "Subscription to the newsletter", "<div id='main'>Ciao! Benvenuto nella mia newsletter :)</div>");
Sbaglio qualcosa nel formattarla correttamente? Oppure Altervista non permette di mandarle in quel modo?

LinkBack URL
About LinkBacks


