Пример #1
0
 public function testSendMailSMTP()
 {
     date_default_timezone_set("Asia/Tokyo");
     $ome = new OME();
     $ome->setSmtpInfo($this->smtpSettings);
     $ome->setToField($this->mailAddress, "Masayuki Nii");
     $ome->setFromField($this->mailAddress, "新居雅行");
     $ome->setCurrentDateToHead();
     $ome->setSubject("INTER-Mediator ユニットテスト: testSendMailSMTP");
     $ome->setBody("INTER-Mediator Uni Test: testSendMailSMTP");
     $ome->appendBody("\nINTER-Mediator Uni Test: testSendMailSMTP");
     $ome->appendBody("\nINTER-Mediator ユニットテスト: testSendMailSMTP");
     $ome->appendBody("\nINTER-Mediator Uni Test: testSendMailSMTP");
     for ($i = 0; $i < 100; $i++) {
         $ome->appendBody("日本語の「複雑な」構造を、持った文章(sentence)を、書いてみたら、こうなったですぞ。");
     }
     $ome->appendBody("\nこれが最後です。");
     $result = $ome->send();
     $this->assertEquals($result, true, "[ERROR] in sending mail");
 }
 public function processing($sendMailParam, $result, $smtpConfig)
 {
     $ome = new OME();
     if (isset($sendMailParam['f-option']) && $sendMailParam['f-option'] === true) {
         $ome->useSendMailParam();
     }
     if (isset($sendMailParam['body-wrap']) && $sendMailParam['body-wrap'] > 1) {
         $ome->setBodyWidth($sendMailParam['body-wrap']);
     }
     $altSMTPConfig = $this->getSmtpConfigFromParams();
     if ($altSMTPConfig !== false && is_array($altSMTPConfig)) {
         $smtpConfig = $altSMTPConfig;
     }
     if (isset($smtpConfig) && is_array($smtpConfig)) {
         if (isset($smtpConfig['password'])) {
             $ome->setSmtpInfo(array('host' => $smtpConfig['server'], 'port' => $smtpConfig['port'], 'protocol' => 'SMTP_AUTH', 'user' => $smtpConfig['username'], 'pass' => $smtpConfig['password']));
         } else {
             $ome->setSmtpInfo(array('host' => $smtpConfig['server'], 'port' => $smtpConfig['port'], 'protocol' => 'SMTP'));
         }
     }
     if (isset($sendMailParam['to-constant'])) {
         $ome->setToField($sendMailParam['to-constant']);
     } else {
         if (isset($result[0]) && isset($sendMailParam['to']) && isset($result[0][$sendMailParam['to']])) {
             $ome->setToField($result[0][$sendMailParam['to']]);
         }
     }
     if (isset($sendMailParam['cc-constant'])) {
         $ome->setToField($sendMailParam['cc-constant']);
     } else {
         if (isset($result[0]) && isset($sendMailParam['cc']) && isset($result[0][$sendMailParam['cc']])) {
             $ome->setCcField($result[0][$sendMailParam['cc']]);
         }
     }
     if (isset($sendMailParam['bcc-constant'])) {
         $ome->setToField($sendMailParam['bcc-constant']);
     } else {
         if (isset($result[0]) && isset($sendMailParam['bcc']) && isset($result[0][$sendMailParam['bcc']])) {
             $ome->setBccField($result[0][$sendMailParam['bcc']]);
         }
     }
     if (isset($sendMailParam['from-constant'])) {
         $ome->setFromField($sendMailParam['from-constant']);
     } else {
         if (isset($result[0]) && isset($sendMailParam['from']) && isset($result[0][$sendMailParam['from']])) {
             $ome->setFromField($result[0][$sendMailParam['from']]);
         }
     }
     if (isset($sendMailParam['subject-constant'])) {
         $ome->setSubject($sendMailParam['subject-constant']);
     } else {
         if (isset($result[0]) && isset($sendMailParam['subject']) && isset($result[0][$sendMailParam['subject']])) {
             $ome->setSubject($result[0][$sendMailParam['subject']]);
         }
     }
     if (isset($sendMailParam['body-template'])) {
         $ome->setTemplateAsFile(dirname($_SERVER["SCRIPT_FILENAME"]) . '/' . $sendMailParam['body-template']);
         $dataArray = array();
         if (isset($sendMailParam['body-fields'])) {
             foreach (explode(',', $sendMailParam['body-fields']) as $fieldName) {
                 if (isset($result[0]) && isset($result[0][$fieldName])) {
                     $dataArray[] = $result[0][$fieldName];
                 } else {
                     $dataArray[] = '';
                 }
             }
         }
         $ome->insertToTemplate($dataArray);
     } else {
         if (isset($sendMailParam['body-constant'])) {
             $ome->setBody($sendMailParam['body-constant']);
         } else {
             if (isset($result[0]) && $sendMailParam['body'] && isset($result[0][$sendMailParam['body']])) {
                 $ome->setBody($result[0][$sendMailParam['body']]);
             }
         }
     }
     if (!$ome->send()) {
         return $ome->getErrorMessage();
     }
     return true;
 }