Tag Archive for email

Assure a valid email that .Net can actually send an email to is passed.

protected void ValidEmail(object source, ServerValidateEventArgs args)
		{
			try
			{
				var a = new MailAddress(args.Value);
			}
			catch (Exception ex)
			{
				args.IsValid = false;
				return;
			}
			args.IsValid = true;
		}

source

CHECK VALID EMAIL ADDRESS JQUERY

$(function(){
 
var email = $("input#email").val();
	if(isValidEmailAddress(email)) {
		$(email).after("hooray!");
	} else {
		$(email).addClass("yourerror").after("<label class='error'>Email is not valid!</label>").focus();
		return false;
	}
});
 
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[w-s]+")|([w-]+(?:.[w-]+)*)|("[w-s]+")([w-]+(?:.[w-]+)*))(@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$)|(@[?((25[0-5].|2[0-4][0-9].|1[0-9]{2}.|[0-9]{1,2}.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2}).){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})]?$)/i);
return pattern.test(emailAddress);
}

source

EMAIL VALIDATOR

!preg_match('/^([a-z0-9]([a-z0-9_-]*.?[a-z0-9])*)(+[a-z0-9]+)?@([a-z0-9]([a-z0-9-]*[a-z0-9])*.)*([a-z0-9]([a-z0-9-]*[a-z0-9]+)*).[a-z]{2,6}$/', $_POST['user']['email']))

source

validate email php

function check_email_address($email) {
  // First, we check that there's one @ symbol, and that the lengths are right
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    return false;
  }
  // Split it into sections to make life easier
  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++) {
    if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~.-]{0,63})|("[^(|")]{0,62}"))$", $local_array[$i])) {
      return false;
    }
  }
  if (!ereg("^[?[0-9.]+]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
    $domain_array = explode(".", $email_array[1]);
    if (sizeof($domain_array) < 2) {
      return false; // Not enough parts to domain
    }
    for ($i = 0; $i < sizeof($domain_array); $i++) {
      if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
        return false;
      }
    }
  }
  return true;
}

source

Send Hassle Free and Dependable HTML Emails With PHP

function htmlmail($to, $subject, $message, $headers = NULL)
{
	$mime_boundary = md5(time()); 

	$headers .= "
Message-ID: <" . time() . " TheSystem@{$_SERVER['SERVER_NAME']}>
";
	$headers .= "X-Mailer: PHP " . phpversion() . "
";
	$headers .= "MIME-Version: 1.0
";
	$headers .= "Content-Type: multipart/alternative;boundary={$mime_boundary}

";

	$newmessage = "This is a multi-part message in MIME format.";
	$newmessage .= "

--{$mime_boundary}
";
	$newmessage .= "Content-type: text/plain;charset=utf-8

";
	$newmessage .= strip_tags(str_replace(array('<br>', '<br />'), "
", $message)) . "

";

	$newmessage .= "

--{$mime_boundary}
";
	$newmessage .= "Content-type: text/html;charset=utf-8

";

	// prepended HTML
	$newmessage .= '<body style="margin:0"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="#ffffff" valign="top"><table width="750" border="0" cellpadding="0" cellspacing="0" align="center"><tr><td bgcolor="#ffffff" width="750">';

	// HTML message that was passed to this function
	$newmessage .= $message;

	// appended HTML
	$newmessage .= '</td></tr></table></td></tr></table></body>';

	return mail($to, $subject, $newmessage, $headers);
}

source

using sendEmail perl script and Gmail SMTP server to send email

./sendEmail -f <a href="mailto:fromadd@site.com">fromadd@site.com</a> -t <a href="mailto:toadd@site.com">toadd@site.com</a> -u "Testing sendEmail script" -m "it works" -s smtp.gmail.com -xu gmailUsername -xp gmailPassword

source

HTML Email Function

/*
EXAMPLE: htmlmail('<a href="mailto:user@domain.com">user@domain.com</a>', 'Look ma, HTML e-mails','You just got <a href="<a href="http://www.yougotrickrolled.com/">Rick" >http://www.yougotrickrolled.com/">Rick</a> Rolled</a>');
NOTE: $headers is optional, but can be used to set From, CC, etc. Go to <a href="http://www.htmlite.com/php029.php" >http://www.htmlite.com/php029.php</a> for info
*/

function htmlmail($to, $subject, $message, $headers = NULL)
{
	$mime_boundary = md5(time()); 

	$headers .= "
Message-ID: <" . time() . " TheSystem@{$_SERVER['SERVER_NAME']}>
";
	$headers .= "X-Mailer: PHP " . phpversion() . "
";
	$headers .= "MIME-Version: 1.0
";
	$headers .= "Content-Type: multipart/alternative;boundary={$mime_boundary}

";

	$newmessage = "This is a multi-part message in MIME format.";
	$newmessage .= "

--{$mime_boundary}
";
	$newmessage .= "Content-type: text/plain;charset=utf-8

";
	$newmessage .= strip_tags(str_replace(array('<br>', '<br />'), "
", $message)) . "

";

	$newmessage .= "

--{$mime_boundary}
";
	$newmessage .= "Content-type: text/html;charset=utf-8

";

	// prepended HTML
	$newmessage .= '<body style="margin:0"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="#ffffff" valign="top"><table width="750" border="0" cellpadding="0" cellspacing="0" align="center"><tr><td bgcolor="#ffffff" width="750">';

	// HTML message that was passed to this function
	$newmessage .= $message;

	// appended HTML
	$newmessage .= '</td></tr></table></td></tr></table></body>';

	return mail($to, $subject, $newmessage, $headers);
}

source

create and send an email with applescript

tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:"Subject text", content:"Content text", visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties {address:"email address"}
send
end tell
end tell

source

doctype for html emails

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2.<html xmlns="http://www.w3.org/1999/xhtml">

source

Email Obfuscation (ASCII)

function safeEmail($email)
{

$obfuscatedEmail = '';
$email           = eregi_replace('#','', $email);
$length          = strlen($email);

for ($i = 0; $i < $length; $i++)
{
$obfuscatedEmail .= "&#" . ord($email[$i]);
}

$return = '<a href="mailto:' . $obfuscatedEmail . '">'.$obfuscatedEmail.'</a>';

return $return;
}

source