PHP Tutorial

PHP + SQL Scripts Functions Classes
PHP \ Function \ send_mail
Last modi. : 23-March-2023 00:13:45

Sign-in -> Login
function send_email($email, $from, $subject, $message, $headers = null)
{
	// Unique boundary
	$boundary = md5( uniqid() . microtime() );

	// If no $headers sent
	if (empty($headers))
	{
		// Add From: header
		$headers = "From: " . $from->name . " <" . $from->email . ">\r\n";

		// Specify MIME version 1.0
		$headers .= "MIME-Version: 1.0\r\n";

		// Tell e-mail client this e-mail contains alternate versions
		$headers .= "Content-Type: multipart/alternative; boundary=\"$boundary\"\r\n\r\n";
	}

	// Plain text version of message
	$body = "--$boundary\r\n" .
	   "Content-Type: text/plain; charset=ISO-8859-1\r\n" .
	   "Content-Transfer-Encoding: base64\r\n\r\n";
	$body .= chunk_split( base64_encode( strip_tags($message) ) );

	// HTML version of message
	$body .= "--$boundary\r\n" .
	   "Content-Type: text/html; charset=ISO-8859-1\r\n" .
	   "Content-Transfer-Encoding: base64\r\n\r\n";
	$body .= chunk_split( base64_encode( $message ) );

	$body .= "--$boundary--";

	// Send Email
	if (is_array($email))
	{
		foreach ($email as $e)
		{
			mail($e, $subject, $body, $headers);
		}
	}
	else
	{
		mail($email, $subject, $body, $headers);
	}
}
$message='<div style="background-color:#F93154; color:#FBFBFB; text-align:center; font-size:170%; font-variant: small-caps; line-height:50px;"><strong>YourDomain.com
</strong></div>';
$message .='<div ><strong>Your order has been placed!</strong></div>';
$obj = (object) array('name' => 'Clean-and-Safe.Shop', 'email'=>'noreply@clean-and-safe.shop');
send_email("info@clean-and-safe.shop", $obj, "Test Mail", $message);