Created
July 18, 2018 13:50
-
-
Save kobus1998/24ff0faac417376faf28bb7cdd41ef25 to your computer and use it in GitHub Desktop.
PHP Validate mail body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Make sure lines are right length in mail body | |
* @param string mail body | |
* @param int max line length (default 68) | |
* @param bool only return bool instead of modified body (default false) | |
* @return string|bool validated body | |
*/ | |
function validateMailBody($sBody, $iMaxLen = 68, $bReturnBool = false) | |
{ | |
$bIsValid = preg_match('//u', $sBody); | |
$aResult = []; | |
foreach(preg_split("/\r\n|\n/", $sBody) as $sPart) | |
{ | |
if (strlen($sPart) > $iMaxLen) | |
{ | |
if ($bReturnBool) | |
{ | |
$bIsValid = false; | |
break; | |
} | |
$aResult = array_merge($aResult, str_split($sPart, $iMaxLen)); | |
continue; | |
} | |
$aResult[] = $sPart; | |
} | |
if ($bReturnBool) | |
{ | |
return $bIsValid; | |
} | |
return implode("\r\n", $aResult); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment