예제 #1
0
 /**
  * Creates a valid email address for the sender of mail messages.
  *
  * Uses a fallback chain:
  * $TYPO3_CONF_VARS['MAIL']['defaultMailFromAddress'] ->
  * no-reply@FirstDomainRecordFound ->
  * no-reply@php_uname('n') ->
  * no-reply@example.com
  *
  * Ready to be passed to $mail->setFrom()
  *
  * @return string An email address
  */
 public static function getSystemFromAddress()
 {
     // default, first check the localconf setting
     $address = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
     if (!GeneralUtility::validEmail($address)) {
         // just get us a domain record we can use as the host
         $host = '';
         $domainRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('domainName', 'sys_domain', 'hidden = 0', '', 'pid ASC, sorting ASC');
         if (!empty($domainRecord['domainName'])) {
             $tempUrl = $domainRecord['domainName'];
             if (!GeneralUtility::isFirstPartOfStr($tempUrl, 'http')) {
                 // shouldn't be the case anyways, but you never know
                 // ... there're crazy people out there
                 $tempUrl = 'http://' . $tempUrl;
             }
             $host = parse_url($tempUrl, PHP_URL_HOST);
         }
         $address = 'no-reply@' . $host;
         if (!GeneralUtility::validEmail($address)) {
             // still nothing, get host name from server
             $address = 'no-reply@' . php_uname('n');
             if (!GeneralUtility::validEmail($address)) {
                 // if everything fails use a dummy address
                 $address = '*****@*****.**';
             }
         }
     }
     return $address;
 }