* @link https://www.oxidmodule.com */ declare(strict_types=1); namespace D3\SmtpChecker\Application\Controller\Admin; use Assert\Assert; use Assert\InvalidArgumentException; use Net_SMTP; use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController; use OxidEsales\Eshop\Application\Model\Shop; use OxidEsales\Eshop\Core\Registry; use PEAR; class SmtpChecker extends AdminDetailsController { protected bool $debug = true; protected string $host; protected Net_SMTP $smtp; public function __construct() { parent::__construct(); /** @var Shop $activeShop */ $activeShop = Registry::getConfig()->getActiveShop(); $this->host = Registry::getRequest()->getRequestEscapedParameter('') ?? $activeShop->getFieldData('oxsmtp'); $this->checkDataAreSet(); $this->hostIsAvailable(); /* //$host = 'cloud1-vm279.de-nserver.de:587'; $from = 'mail@ds.data-develop.de'; $rcpt = array('test@ds.data-develop.de', 'test@daniel-seifert.com', 'recipient2@example.com'); //$rcpt = array('test@ds.data-develop.de'); $rcpt = array('test@daniel-seifert.com'); $subj = "Subject: Test Message\n"; $body = "Body Line 1\nBody Line 2"; if ( PEAR::isError( $e = $smtp->connect())) { dumpvar(__METHOD__.__LINE__.PHP_EOL); die($e->getMessage() . "\n"); } if ( PEAR::isError( $smtp->mailFrom( $from))) { die("Unable to set sender to $from\n"); } foreach ($rcpt as $to) { dumpvar($to.PHP_EOL); if ( PEAR::isError( $res = $smtp->rcptTo( $to))) { die("Unable to add recipient $to: " . $res->getMessage() . "\n"); } } /* Set the body of the message. */ /* if ( PEAR::isError( $res = $smtp->data( $subj . "\r\n" . $body))) { dumpvar($res->getMessage()); die("Unable to send data\n"); } /* Disconnect from the SMTP server. */ /* $smtp->disconnect(); */ } protected function checkDataAreSet() { } /** * @throws InvalidArgumentException * @return void */ protected function hostIsAvailable() { $this->host = 'test.example.dev'; Assert::that(( $this->smtp = new Net_SMTP( $this->host ) ))->true('Unable to instantiate SMTP object'); $this->smtp->setDebug($this->debug); } protected function foo() { PEAR::isError( $e = $this->smtp->connect()); dumpvar(get_class($e)); die(); Assert::that(PEAR::isError( $e = $this->smtp->connect()))->false($e->getMessage()); { dumpvar(__METHOD__.__LINE__.PHP_EOL); die($e->getMessage() . "\n"); } } }