Return to Snippet

Revision: 33429
at October 9, 2010 00:46 by stz184


Updated Code
function send_mail($to, $subject, $message, $from_name, $from_email, $reply_to_name=false, $reply_to_email=false) {
	if($reply_to_name == false) $reply_to_name = $from_name;
	if($reply_to_email == false) $reply_to_email = $from_email;
	if(!preg_match("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}^", $to)){
		return false;
	}
	if(!preg_match("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}^", $from_email)){
		return false;
	}
	if(!preg_match("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}^", $reply_to_email)){
		return false;
	}
	$headers  = 'MIME-Version: 1.0' . PHP_EOL;
	$headers .= 'From: '.$from_name.' <'.$from_email.'>' . PHP_EOL;
	$headers .= 'Reply-To: '.$reply_to_name.' <'.$reply_to_email.'>' . PHP_EOL;
	$headers .= 'Return-Path: '.$from_name.' <'.$from_email.'>' . PHP_EOL;
	$headers .= 'Content-Type: text/html; charset=UTF-8'.PHP_EOL;
	$headers .= 'Content-Transfer-Encoding: base64 '.PHP_EOL;
	$headers .= 'X-Mailer: PHP/' . phpversion();
	
	$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
	$message = chunk_split(base64_encode($message));
	
	if(@mail($to, $subject, $message, $headers)) {
		return true;
	}
	else {
		return false;
	}
}

Revision: 33428
at October 8, 2010 18:25 by stz184


Initial Code
function send_mail($to, $subject, $message, $from_name, $from_email, $reply_to_name=false, $reply_to_email=false) {
	if($reply_to_name == false) $reply_to_name = $from_name;
	if($reply_to_email == false) $reply_to_email = $from_email;
	if(!preg_match("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}^", $to)){
		return false;
	}
	if(!preg_match("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}^", $from_email)){
		return false;
	}
	if(!preg_match("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}^", $reply_to_email)){
		return false;
	}
	$headers  = 'MIME-Version: 1.0' . PHP_EOL;
	$headers .= 'From: '.$from_name.' <'.$from_email.'>' . PHP_EOL;
	$headers .= 'Reply-To: '.$reply_to_name.' <'.$reply_to_email.'>' . PHP_EOL;
	$headers .= 'Return-Path: '.$from_name.' <'.$from_email.'>' . PHP_EOL;
	$headers .= 'Content-Type: text/html; charset=UTF-8'.PHP_EOL;
	$headers .= 'Content-Transfer-Encoding: base64 '.PHP_EOL;
	$headers .= 'X-Mailer: PHP/' . phpversion();
	
	$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
	$message = chunk_split(base64_encode($message));
	
	mb_language("uni");
	if(@mail($to, $subject, $message, $headers)) {
		return true;
	}
	else {
		return false;
	}
}

Initial URL

                                

Initial Description
Parameters:\r\n- $to - email address to send the mail\r\n- $subject - subject\r\n- $message - message body (HTML allowed)\r\n- $from_name - sender\'s name\r\n- $from_email - sender\'s email\r\n- $reply_to_name = custom, different from $from_name name to be used for replying to this message\r\n- $reply_to_email = custom, different from $from_email email to be used for replying to this message

Initial Title
Send UTF-8 encoded mail with custom to and reply-to

Initial Tags
mail

Initial Language
PHP