Skip to content

Instantly share code, notes, and snippets.

@gheja
Created May 23, 2018 23:20
Show Gist options
  • Save gheja/8a775682b0aca3205d06b2454f1ab733 to your computer and use it in GitHub Desktop.
Save gheja/8a775682b0aca3205d06b2454f1ab733 to your computer and use it in GitHub Desktop.
<?php
$email = "recipient@example.com";
$sender = "Sender <sender@example.com>";
$subject = "A test e-mail";
$body_html = "<html>
<head>
<style type=\"text/css\">
html, body
{
text-align: center;
background: #eee;
font-family: Arial;
padding: 0;
margin: 0;
}
.content
{
width: 600px;
margin: 0 auto 0 auto;
background: #fff;
padding: 32px 16px 128px 16px;
text-align: left;
}
</style>
</head>
<body>
<div class=\"content\">
<h1>Hello test,</h1>
<p>
this is an e-mail.
</p>
</div>
</body>
</html>";
$body_text = "Hello Test,
this is an e-mail.";
$boundary = "----" . substr(hash("sha256", openssl_random_pseudo_bytes(64)), 0, 32);
$headers =
"From: " . $sender . "\n" .
"Reply-To: " . $sender . "\n" .
"Content-Type: multipart/alternative;\n" .
"\tboundary=\"" . $boundary . "\"\n" .
"MIME-Version: 1.0";
$body =
"This is a multipart message in MIME format.\n".
"\n".
"--" . $boundary . "\n" .
"Content-Type: text/plain; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 8bit\n" .
"\n".
$body_text . "\n" .
"--" . $boundary . "\n" .
"Content-Type: text/html; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 8bit\n" .
"\n" .
$body_html . "\n" .
"--" . $boundary . "--\n";
$result = mail($email, $subject, $body, $headers);
if ($result)
{
echo "sent";
}
else
{
echo "failed to send";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment