/** * MAIL FROM * @param $fromUser * @param $fromDomain * @throws \SmtpValidatorEmail\Exception\ExceptionNoHelo */ public function mailFrom($fromUser, $fromDomain) { if (!$this->transport->getSmtp()->mail($fromUser . '@' . $fromDomain)) { // MAIL FROM not accepted, we can't talk $this->statusManager->setStatus($this->users, $this->dom, $this->options['noCommIsValid'], 'MAIL FROM not accepted'); } }
/** * Receives lines from the remote host and looks for expected response codes. * * @param string|array $codes A list of one or more expected response codes * @param int $timeout The timeout for this individual command, if any * * @return string The last text message received * @throws Exception\ExceptionUnexpectedResponse */ public function expect($codes, $timeout = null) { if (!is_array($codes)) { $codes = (array) $codes; } $code = null; $text = ''; try { $text = $line = $this->recv($timeout); while (preg_match("/^[0-9]+-/", $line)) { $line = $this->recv($timeout); $text .= $line; } sscanf($line, '%d%s', $code, $text); if ($code === null || !in_array($code, $codes)) { $this->statusManager->setStatus($this->users, new Domain($this->domain), 0, 'UnexpectedResponse: ' . $line); //throw new Exception\ExceptionUnexpectedResponse($line); } } catch (Exception\ExceptionNoResponse $e) { // no response in expect() probably means that the // remote server forcibly closed the connection so // lets clean up on our end as well? $this->disconnect(false); } return $text; }
/** * Sends a command to the remote host. * * @param string $cmd The cmd to send * * @return int|bool Number of bytes written to the stream * @throws Exception\ExceptionNoConnection * @throws Exception\ExceptionSendFailed */ public function send($cmd) { // must be connected if (!$this->isConnect()) { $this->statusManager->setStatus($this->users, new Domain($this->domain), 0, 'No connection'); return false; } $result = false; // write the cmd to the connection stream try { if ($this->validationOptions['debug'] === true) { $this->debug[] = ["timestamp" => microtime(true), "message" => "send> {$cmd}"]; } $result = fwrite($this->socket, $cmd . self::CRLF); } catch (\Exception $e) { // did the send work? if ($result === false) { $this->statusManager->setStatus($this->users, new Domain($this->domain), 0, 'Send failed on: ' . $this->host); return $result; } } return $result; }