$nameLen2)
{
// so output Jane and John Smith
$varNames = $arr_name1[0] . " and " . $arr_name2[0] . " " . $arr_name1[1];
}
// if we have "John Smith" and "Jane"
elseif($nameLen2>$nameLen1)
{
$varNames = $arr_name1[0] . " and " . $arr_name2[0] . " " . $arr_name2[1];
}
// if we haven't satisfied any of the above conditions -- should rarely happen -- just dump it.
else
{
$varNames=$varName1 . ' and '. $varName2;
}
}
else
{
$varNames = $varName1;
}
// spit out the string.
return $varNames;
}
/*
this function takes a phone number in the database format
and formats it like (613)555-4321.
returns a string, so call this function like this:
$myvariable = format_phone($param1);
*/
function Str_Format_Phone($var_PhoneNumber)
{
if ($var_PhoneNumber)
{
$LengthOfTelephoneNumber=strlen($var_PhoneNumber);
if ($LengthOfTelephoneNumber==10)
{
$PhoneAC = substr("$var_PhoneNumber", 0, 3);
$PhonePrefix = substr("$var_PhoneNumber", 3, 3);
$PhoneSuffix = substr("$var_PhoneNumber", 6, 4);
$var_PhoneNumber = "(".$PhoneAC.") ".$PhonePrefix."-".$PhoneSuffix;
}
elseif($LengthOfTelephoneNumber==11)
{
$PhoneCC = substr("$var_PhoneNumber", 0, 1);
$PhoneAC = substr("$var_PhoneNumber", 1, 3);
$PhonePrefix = substr("$var_PhoneNumber", 4, 3);
$PhoneSuffix = substr("$var_PhoneNumber", 7, 4);
$var_PhoneNumber = "$PhoneCC (".$PhoneAC.") ".$PhonePrefix."-".$PhoneSuffix;
}
}
return $var_PhoneNumber;
}
// returns xth for days, useful for the xth day of month, year.
function Str_Get_th_day_of_month_year($var_date)
{
// echo $var_date;
$arr_date = array();
$arr_date = explode("-", $var_date);
// print_r($arr_date);
// handle the day
// special cases here.
if ($arr_date[2] == "01")
$var_f_date = "1st";
elseif ($arr_date[2] == "02")
$var_f_date = "2nd";
elseif ($arr_date[2]=="03")
$var_f_date = "3rd";
elseif ($arr_date[2]=="21")
$var_f_date = "21st";
elseif ($arr_date[2]=="22")
$var_f_date = "22nd";
elseif ($arr_date[2]=="23")
$var_f_date = "23rd";
elseif ($arr_date[2]=="31")
$var_f_date = "31st";
// everything else just gets Xth
else
{
// trim off the first zero if there is one.
if($arr_date[2] < 10)
{
$var_date = $arr_date[2];
$var_f_date = ltrim($arr_date[2], "0");
$var_f_date .= "th";
}
else
$var_f_date = $arr_date[2] . "th";
}
// handle the month
$arr_date[1] = GetLongMonth($arr_date[1]);
$var_F_Date = $var_f_date . " day of " .$arr_date[1] .", " .$arr_date[0];
// echo "returning $var_F_Date
";
return $var_F_Date;
}
function GetMonthNumber($Month2Convert)
{
if (($Month2Convert=="Jan")||($Month2Convert=="January"))
{
return("01");
}
if (($Month2Convert=="Feb")||($Month2Convert=="February"))
{
return("02");
}
if (($Month2Convert=="Mar")||($Month2Convert=="March"))
{
return("03");
}
if (($Month2Convert=="Apr")||($Month2Convert=="April"))
{
return("04");
}
if ($Month2Convert=="May")
{
return("05");
}
if (($Month2Convert=="Jun")||($Month2Convert=="June"))
{
return("06");
}
if (($Month2Convert=="Jul")||($Month2Convert=="July"))
{
return("07");
}
if (($Month2Convert=="Aug")||($Month2Convert=="August"))
{
return("08");
}
if (($Month2Convert=="Sep")||($Month2Convert=="Sept")||($Month2Convert=="September"))
{
return("09");
}
if (($Month2Convert=="Oct")||($Month2Convert=="October"))
{
return("10");
}
if (($Month2Convert=="Nov")||($Month2Convert=="November"))
{
return("11");
}
if (($Month2Convert=="Dec")||($Month2Convert=="December"))
{
return("12");
}
}
// this is deprecated, should be replaced with SendMailVince, but need to test first, as everyone uses it.
function SendMail($From,$FromName,$To,$ToName,$Subject,$Text,$Html,$AttmFiles)
{
$OB="----=_OuterBoundary_000";
$IB="----=_InnerBoundary_001";
$Html=$Html?$Html:preg_replace("/\n/","
",$Text) or die("neither text nor html part present.");
$Text=$Text?$Text:"Sorry, but you need an html mailer to read this mail.";
$From or die("sender address missing");
$To or die("recipient address missing");
// echo "
in sendmail, to is $To
";
$headers ="MIME-Version: 1.0\r\n";
$headers.="From: ".$FromName." <".$From.">\n";
// $headers.=($ToName)? "To: ". $ToName ." <".$To.">\n":"";
$headers.="To: ". $ToName ." <".$To.">\n";
$headers.="Cc: ".$FromName." <".$From.">\n";
$headers.="BCC: System \n";
$headers.="Reply-To: ".$FromName." <".$From.">\n";
$headers.="X-Priority: 1\n";
$headers.="X-MSMail-Priority: High\n";
$headers.="X-Mailer: My PHP Mailer\n";
$headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$IB."\"\n";
$Msg ="This is a multi-part message in MIME format.\n";
// $Msg.="\n--".$OB."\n";
// $Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n";
//plaintext section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
// plaintext goes here
$Msg.=$Text."\n\n";
if($Html)
{
// html section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: base64\n\n";
// html goes here
$Msg.=chunk_split(base64_encode($Html))."\n\n";
}
// end of IB
// $Msg.="\n--".$IB."--\n";
// echo $Msg;
// attachments
// echo "
attmfiles is $AttmFiles
";
if($AttmFiles)
{
foreach($AttmFiles as $AttmFile)
{
// echo "
attmfile is $AttmFile
";
$patharray = explode ("/", $AttmFile);
$FileName=$patharray[count($patharray)-1];
// echo "
filename is $FileName
";
$Msg.= "\n--".$IB."\n";
$Msg.="Content-Type: application/octetstream;\n\tname=\"".$FileName."\"\n";
$Msg.="Content-Transfer-Encoding: base64\n";
$Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n";
//file goes here
$fd=fopen ($AttmFile, "r");
$FileContent=fread($fd,filesize($AttmFile));
fclose ($fd);
$FileContent=chunk_split(base64_encode($FileContent));
$Msg.=$FileContent;
$Msg.="\n\n";
}
}
//message ends
$Msg.="\n--".$IB."--\n";
$var_Pass_Fail = mail($To,$Subject,$Msg,$headers);
return $var_Pass_Fail;
}
function SendMailVince($From,$FromName,$To,$ToName,$Subject,$Text,$Html,$AttmFiles)
{
// echo $AttmFiles[0];
$var_AttmTemp = $AttmFiles[0];
// echo "Got called with From: $From fromname: $FromName To: $To ToName: $ToName Subject: $Subject Text: $Text HTML: $Html Attach: $var_AttmTemp
";
// for multiple recipients
$arr_toMultiple = array();
$arr_toMultiple = explode(" ", $To);
foreach($arr_toMultiple as $sendto)
{
$to .= $sendto.', ';
}
$tolen = strlen($to);
$to = substr($to, 0, ($tolen-2));
//define the receiver of the email
//define the subject of the email
$subject = $Subject;
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: $From\r\nReply-To: $From\r\n";
$headers.="CC: $From\r\nReply-To: $From\r\n";
$headers.="BCC: system@buildersit.com\r\n";
//add boundary string and mime type specification
$headers .= " \r\nMIME-Version: 1.0";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
// $attachment = chunk_split(base64_encode(file_get_contents('temp.pdf')));
$patharraytemp = explode ("/", $AttmFiles[0]);
$FileName_temp=$patharraytemp[count($patharraytemp)-1];
// echo "file name is $FileName_temp
";
//define the body of the message.
ob_start(); //Turn on output buffering
?>This is a multi-part message in MIME format.
--PHP-mixed-
Content-Type: multipart/alternative;
boundary="PHP-alt-"
--PHP-alt-
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
--PHP-alt-
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
$Html