Skip to content

Instantly share code, notes, and snippets.

@sergejmueller
Created December 7, 2016 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergejmueller/10cbb46b94f3177eb7359fdefd5d3809 to your computer and use it in GitHub Desktop.
Save sergejmueller/10cbb46b94f3177eb7359fdefd5d3809 to your computer and use it in GitHub Desktop.
Email test to check the 102 KB email size limit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Your Message Subject or Title</title>
<style type="text/css">
</style>
</head>
<body>
<table>
<tr><td>%%content%%</td></tr>
</table>
</body>
</html>
<?php
$emailContent = '';
$emailTemplate = file_get_contents('email.html');
$maxSize = 102*1024;
$contentPlaceholder = '%%content%%';
$sizeDifferenze = $maxSize - strlen($emailTemplate) + strlen($contentPlaceholder);
for ($i = 1; $i <= $sizeDifferenze / 4; $i++) {
$emailContent .= substr( md5(microtime()),rand(0,26),3) . ' ';
}
$html = str_replace($contentPlaceholder, $emailContent, $emailTemplate);
echo $html;
echo strlen($html);
exit;
$to = 'test@test.de';
$subject = 'HTML Test';
$headers = "From: test@test.de\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
echo mail($to, $subject, $html, $headers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment