Send Email Function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Send Email Function

Post by dibyendrah »

Customized function to send email.

Code: Select all

// Function to Send out Email
function Send_Email($sFrEmail, $sToEmail, $sCcEmail, $sBccEmail, $sSubject, $sMail, $sFormat)
{
	/* recipients */
	$to  = $sToEmail;

	/* subject */
	$subject = $sSubject;

	$headers = "";

	if ($sFormat == "html") {
		$content_type = "text/html";
	} else {
		$content_type = "text/plain";
	}

	$headers = "Content-type: " . $content_type . "\r\n";

	$message = $sMail;

	/* additional headers */
	$headers .= "From: " . $sFrEmail . "\r\n";
	if ($sCcEmail <> "") {
		$headers .= "Cc: " . $sCcEmail . "\r\n";
	}
	if ($sBccEmail <>"") {
		$headers .= "Bcc: " . $sBccEmail . "\r\n";
	}

	/* and now mail it */
	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
		ini_set("SMTP","localhost");
		ini_set("smtp_port","25");
	}
	ini_set("sendmail_from",$sFrEmail);
	mail($to, $subject, $message, $headers);

}

Cheers,
Dibyendra
Post Reply