PHPMailer\PHPMailer\PHPMailer::setLanguage PHP Method

setLanguage() public method

Returns false if it cannot load the language file. The default language is English.
public setLanguage ( string $langcode = 'en', string $lang_path = '' ) : boolean
$langcode string ISO 639-1 2-character language code (e.g. French is "fr")
$lang_path string Path to the language file directory, with trailing separator (slash)
return boolean
    public function setLanguage($langcode = 'en', $lang_path = '')
    {
        // Define full set of translatable strings in English
        $PHPMAILER_LANG = ['authenticate' => 'SMTP Error: Could not authenticate.', 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', 'data_not_accepted' => 'SMTP Error: data not accepted.', 'empty_message' => 'Message body empty', 'encoding' => 'Unknown encoding: ', 'execute' => 'Could not execute: ', 'file_access' => 'Could not access file: ', 'file_open' => 'File Error: Could not open file: ', 'from_failed' => 'The following From address failed: ', 'instantiate' => 'Could not instantiate mail function.', 'invalid_address' => 'Invalid address: ', 'mailer_not_supported' => ' mailer is not supported.', 'provide_address' => 'You must provide at least one recipient email address.', 'recipients_failed' => 'SMTP Error: The following recipients failed: ', 'signing' => 'Signing Error: ', 'smtp_connect_failed' => 'SMTP connect() failed.', 'smtp_error' => 'SMTP server error: ', 'variable_set' => 'Cannot set or reset variable: ', 'extension_missing' => 'Extension missing: '];
        if (empty($lang_path)) {
            // Calculate an absolute path so it can work if CWD is not here
            $lang_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR;
        }
        $foundlang = true;
        $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
        // There is no English translation file
        if ('en' != $langcode) {
            // Make sure language file path is readable
            if (!file_exists($lang_file)) {
                $foundlang = false;
            } else {
                // Overwrite language-specific strings.
                // This way we'll never have missing translation keys.
                $foundlang = (include $lang_file);
            }
        }
        $this->language = $PHPMAILER_LANG;
        return (bool) $foundlang;
        // Returns false if language not found
    }

Usage Example

コード例 #1
1
ファイル: PhpMailer.php プロジェクト: jetfirephp/mailer
 /**
  *
  */
 private function config()
 {
     if (isset($this->config['lang']['local']) && isset($this->config['lang']['path'])) {
         $this->mail->setLanguage($this->config['lang']['local'], $this->config['lang']['path']);
     }
     $this->mail->CharSet = $this->config['charset'];
     switch ($this->config['transport']) {
         case 'smtp':
             $this->mail->isSMTP();
             if (isset($this->config['debug'])) {
                 $this->mail->SMTPDebug = $this->config['debug'];
                 $this->mail->Debugoutput = 'html';
             }
             $this->mail->Host = $this->config['host'];
             if (isset($this->config['user'])) {
                 $this->mail->SMTPAuth = true;
                 $this->mail->Username = $this->config['user'];
                 $this->mail->Password = $this->config['pass'];
                 $this->mail->Port = $this->config['port'];
                 if (isset($this->config['encrypt'])) {
                     $this->mail->SMTPSecure = $this->config['encrypt'];
                 }
             }
             break;
         case 'sendmail':
             $this->mail->isSendmail();
             $this->mail->Sendmail = $this->config['command'];
             break;
     }
 }