PHP Classes

not working on my hostinger server

Recommend this page to a friend!

      Verify e-mail  >  All threads  >  not working on my hostinger server  >  (Un) Subscribe thread alerts  
Subject:not working on my hostinger server
Summary:please explain configuration
Messages:4
Author:malender malender
Date:2023-06-08 13:15:52
 

  1. not working on my hostinger server   Reply   Report abuse  
Picture of malender malender malender malender - 2023-06-08 13:15:52
hello bro , i'm using your script on my server hostinger i get this error


220-cpl17.main-hosting.eu ESMTP Exim 4.96 #2 Thu, 08 Jun 2023 12:53:02 +0000
Connection success gmail-smtp-in.l.google.com
HELO maxtvs.net
220-We do not authorize the use of this system to transport unsolicited,
MAIL FROM:<support@maxtvs.net>
220 and/or bulk e-mail.
RCPT TO:<fars@gmail.com>
250 cpl17.main-hosting.eu Hello maxtvs.net [109.106.251.101]
RSET
QUIT
email <fars@gmail.com> exist!


can you please explain what should be changed in class.verifyEmail.php

  2. Re: not working on my hostinger server   Reply   Report abuse  
Picture of Konstantin Granin Konstantin Granin - 2023-06-08 15:34:55 - In reply to message 1 from malender malender
hi!

1. in "MAIL FROM" use real email
2. make sure DNS records for "maxtvs.net" is valid
"A" record
"MX" record
"PTR" record
"SPF" record
The server running the script should be allowed to send emails on behalf of the domain "maxtvs.net"


The recipient server thinks that you are a spammer, see the answer:
220-We do not authorize the use of this system to transport unsolicited

  3. Re: not working on my hostinger server   Reply   Report abuse  
Picture of Fernando Ingunza Fernando Ingunza - 2024-06-02 03:11:41 - In reply to message 1 from malender malender
Hi, I had same issue, I have to create a new class for hostinger server, here class:

class verifyEmailGoddaddy {

protected $errorEncountered = false;

protected $stream = false;

/**
* SMTP port number
* @var int
*/
protected $port = 465;

/**
* email address for request
* @var string
*/
protected $from = 'root@localhost';

/**
* The connection timeout, in seconds.
* @var int
*/
protected $max_connection_timeout = 30;

/**
* Timeout value on stream, in seconds.
* @var int
*/
protected $stream_timeout = 15;

/**
* Wait timeout on stream, in seconds.
* * 0 - not wait
* @var int
*/
protected $stream_timeout_wait = 0;

/**
* Whether to throw exceptions for errors.
* @type boolean
* @access protected
*/
protected $exceptions = false;

/**
* The number of errors encountered.
* @type integer
* @access protected
*/
protected $error_count = 0;

/**
* class debug output mode.
* @type boolean
*/
public $Debug = false;

/**
* How to handle debug output.
* Options:
* * `echo` Output plain-text as-is, appropriate for CLI
* * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
* * `log` Output to error log as configured in php.ini
* @type string
*/
public $Debugoutput = 'echo';

/**
* SMTP RFC standard line ending.
*/
const CRLF = "\r\n";

/**
* Holds the most recent error message.
* @type string
*/
public $ErrorInfo = '';

/**
* Constructor.
* @param boolean $exceptions Should we throw external exceptions?
*/
public function __construct($exceptions = false) {
$this->exceptions = (boolean) $exceptions;
}

/**
* Set email address for SMTP request
* @param string $email Email address
*/
public function setEmailFrom($email) {
if (!self::validate($email)) {
$this->set_error('Invalid address : ' . $email);
$this->edebug($this->ErrorInfo);
if ($this->exceptions) {
throw new verifyEmailException($this->ErrorInfo);
}
}
$this->from = $email;
}

/**
* Set connection timeout, in seconds.
* @param int $seconds
*/
public function setConnectionTimeout($seconds) {
if ($seconds > 0) {
$this->max_connection_timeout = (int) $seconds;
}
}

/**
* Sets the timeout value on stream, expressed in the seconds
* @param int $seconds
*/
public function setStreamTimeout($seconds) {
if ($seconds > 0) {
$this->stream_timeout = (int) $seconds;
}
}

public function setStreamTimeoutWait($seconds) {
if ($seconds >= 0) {
$this->stream_timeout_wait = (int) $seconds;
}
}

/**
* Validate email address.
* @param string $email
* @return boolean True if valid.
*/
public static function validate($email) {
return (boolean) filter_var($email, FILTER_VALIDATE_EMAIL);
}

/**
* Get array of MX records for host. Sort by weight information.
* @param string $hostname The Internet host name.
* @return array Array of the MX records found.
*/
public function getMXrecords($hostname) {
$mxhosts = array();
$mxweights = array();
if (getmxrr($hostname, $mxhosts, $mxweights) === FALSE) {
$this->set_error('MX records not found or an error occurred');
$this->edebug($this->ErrorInfo);
} else {
array_multisort($mxweights, $mxhosts);
}
/**
* Add A-record as last chance (e.g. if no MX record is there).
* Thanks Nicht Lieb.
* @link http://www.faqs.org/rfcs/rfc2821.html RFC 2821 - Simple Mail Transfer Protocol
*/
if (empty($mxhosts)) {
$mxhosts[] = $hostname;
}
return $mxhosts;
}

/**
* Parses input string to array(0=>user, 1=>domain)
* @param string $email
* @param boolean $only_domain
* @return string|array
* @access private
*/
public static function parse_email($email, $only_domain = TRUE) {
sscanf($email, "%[^@]@%s", $user, $domain);
return ($only_domain) ? $domain : array($user, $domain);
}

/**
* Add an error message to the error container.
* @access protected
* @param string $msg
* @return void
*/
protected function set_error($msg) {
// Check if the error has already been encountered
if (!$this->errorEncountered) {
$this->error_count++;
$this->errorEncountered = true; // Set the flag to true to indicate error encountered
$this->ErrorInfo = $msg;
}
}

/**
* Check if an error occurred.
* @access public
* @return boolean True if an error did occur.
*/
public function isError() {
return ($this->error_count > 0);
}

/**
* Output debugging info
* Only generates output if debug output is enabled
* @see verifyEmail::$Debugoutput
* @see verifyEmail::$Debug
* @param string $str
*/
protected function edebug($str) {
if (!$this->Debug) {
return;
}
switch ($this->Debugoutput) {
case 'log':
//Don't output, just log
error_log($str);
break;
case 'html':
//Cleans up output a bit for a better looking, HTML-safe output
echo htmlentities(
preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, 'UTF-8'
)
. "<br>\n";
break;
case 'echo':
default:
//Normalize line breaks
$str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
"\n", "\n \t ", trim($str)
) . "\n";
}
}

/**
* check up e-mail
* @param string $email Email address
* @return boolean True if the valid email also exist
*/
public function check($email) {
$result = FALSE;

if (!self::validate($email)) {
$this->set_error("{$email} incorrect e-mail");
$this->edebug($this->ErrorInfo);
if ($this->exceptions) {
throw new verifyEmailException($this->ErrorInfo);
}
return FALSE;
}
$this->error_count = 0; // Reset errors
$this->stream = FALSE;

$mxs = $this->getMXrecords(self::parse_email($email));
$timeout = ceil($this->max_connection_timeout / count($mxs));
foreach ($mxs as $host) {
/**
* suppress error output from stream socket client...
* Thanks Michael.
*/
$context = stream_context_create(array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false)));
$this->stream = @stream_socket_client("ssl://{$host}:{$this->port}", $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context);

if ($this->stream === FALSE) {
if ($errno == 0) {
$this->set_error("Problem initializing the socket");
$this->edebug($this->ErrorInfo);
if ($this->exceptions) {
throw new verifyEmailException($this->ErrorInfo);
}
return FALSE;
} else {
$this->edebug($host . ":" . $errstr);
}
} else {
stream_set_timeout($this->stream, $this->stream_timeout);
stream_set_blocking($this->stream, 1);

if ($this->_streamCode($this->_streamResponse()) == '220') {
$this->edebug("Connection success {$host}");
break;
} else {
fclose($this->stream);
$this->stream = FALSE;
}
}
}

if ($this->stream === FALSE) {
$this->set_error("All connection fails");
$this->edebug($this->ErrorInfo);
if ($this->exceptions) {
throw new verifyEmailException($this->ErrorInfo);
}
return FALSE;
}

$this->_streamQuery("EHLO " . self::parse_email($this->from));
$this->_streamResponse();
$this->_streamQuery("MAIL FROM: <{$this->from}>");
$this->_streamResponse();
$this->_streamQuery("RCPT TO: <{$email}>");
$code = $this->_streamCode($this->_streamResponse());
if ($code == '250' || $code == '251') {
$result = TRUE;
} elseif ($code == '550' || $code == '551' || $code == '553' || $code == '511') {
$this->set_error("{$email} not exist");
$this->edebug($this->ErrorInfo);
}
$this->_streamQuery("RSET");
$this->_streamResponse();
$this->_streamQuery("QUIT");
fclose($this->stream);
return $result;
}

/**
* writes the contents of query to the file stream
* @access private
* @return void
*/
private function _streamQuery($query) {
$this->edebug($query);
return fwrite($this->stream, $query . self::CRLF);
}

/**
* Reads all the line long the answer and analyze the response code.
* If an error occurs, returns FALSE
* @access private
* @return string Result text
*/
private function _streamResponse($timed = 0) {
$result = '';
$start_time = time();

// Set the stream to non-blocking mode
stream_set_blocking($this->stream, 0);

while (true) {
$line = @stream_get_line($this->stream, 4096, self::CRLF);

if ($line !== FALSE) {
$result .= $line . self::CRLF;
if (isset($line[3]) && $line[3] != '-') {
break;
}
}

$status = stream_get_meta_data($this->stream);
if (!empty($status['timed_out'])) {
$this->edebug("Timed out while waiting for data! (timeout {$timed} seconds)");
return FALSE;
}

// Check if we have exceeded the read timeout
if (time() - $start_time >= $this->stream_timeout) {
$this->edebug("Stream read timeout exceeded.");
return FALSE;
}

// Sleep briefly to prevent a busy wait
usleep(100000); // 100 milliseconds
}

return $result;
}

/**
* Get Response code from Response
* @param string $str
* @return string
* @access private
*/
private function _streamCode($str) {
preg_match('/^(?<code>[0-9]{3})(\s|-)(.*)$/ims', $str, $matches);
$code = isset($matches['code']) ? $matches['code'] : false;
return $code;
}

}

  4. Re: not working on my hostinger server   Reply   Report abuse  
Picture of Fernando Ingunza Fernando Ingunza - 2024-06-02 03:16:11 - In reply to message 1 from malender malender
Hi, I had same issue, so I had to create a new class for hostinger server, I hope it helps:

class verifyEmailGoddaddy {

protected $errorEncountered = false;

protected $stream = false;

/**
* SMTP port number
* @var int
*/
protected $port = 465;

/**
* email address for request
* @var string
*/
protected $from = 'root@localhost';

/**
* The connection timeout, in seconds.
* @var int
*/
protected $max_connection_timeout = 30;

/**
* Timeout value on stream, in seconds.
* @var int
*/
protected $stream_timeout = 15;

/**
* Wait timeout on stream, in seconds.
* * 0 - not wait
* @var int
*/
protected $stream_timeout_wait = 0;

/**
* Whether to throw exceptions for errors.
* @type boolean
* @access protected
*/
protected $exceptions = false;

/**
* The number of errors encountered.
* @type integer
* @access protected
*/
protected $error_count = 0;

/**
* class debug output mode.
* @type boolean
*/
public $Debug = false;

/**
* How to handle debug output.
* Options:
* * `echo` Output plain-text as-is, appropriate for CLI
* * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
* * `log` Output to error log as configured in php.ini
* @type string
*/
public $Debugoutput = 'echo';

/**
* SMTP RFC standard line ending.
*/
const CRLF = "\r\n";

/**
* Holds the most recent error message.
* @type string
*/
public $ErrorInfo = '';

/**
* Constructor.
* @param boolean $exceptions Should we throw external exceptions?
*/
public function __construct($exceptions = false) {
$this->exceptions = (boolean) $exceptions;
}

/**
* Set email address for SMTP request
* @param string $email Email address
*/
public function setEmailFrom($email) {
if (!self::validate($email)) {
$this->set_error('Invalid address : ' . $email);
$this->edebug($this->ErrorInfo);
if ($this->exceptions) {
throw new verifyEmailException($this->ErrorInfo);
}
}
$this->from = $email;
}

/**
* Set connection timeout, in seconds.
* @param int $seconds
*/
public function setConnectionTimeout($seconds) {
if ($seconds > 0) {
$this->max_connection_timeout = (int) $seconds;
}
}

/**
* Sets the timeout value on stream, expressed in the seconds
* @param int $seconds
*/
public function setStreamTimeout($seconds) {
if ($seconds > 0) {
$this->stream_timeout = (int) $seconds;
}
}

public function setStreamTimeoutWait($seconds) {
if ($seconds >= 0) {
$this->stream_timeout_wait = (int) $seconds;
}
}

/**
* Validate email address.
* @param string $email
* @return boolean True if valid.
*/
public static function validate($email) {
return (boolean) filter_var($email, FILTER_VALIDATE_EMAIL);
}

/**
* Get array of MX records for host. Sort by weight information.
* @param string $hostname The Internet host name.
* @return array Array of the MX records found.
*/
public function getMXrecords($hostname) {
$mxhosts = array();
$mxweights = array();
if (getmxrr($hostname, $mxhosts, $mxweights) === FALSE) {
$this->set_error('MX records not found or an error occurred');
$this->edebug($this->ErrorInfo);
} else {
array_multisort($mxweights, $mxhosts);
}
/**
* Add A-record as last chance (e.g. if no MX record is there).
* Thanks Nicht Lieb.
* @link http://www.faqs.org/rfcs/rfc2821.html RFC 2821 - Simple Mail Transfer Protocol
*/
if (empty($mxhosts)) {
$mxhosts[] = $hostname;
}
return $mxhosts;
}

/**
* Parses input string to array(0=>user, 1=>domain)
* @param string $email
* @param boolean $only_domain
* @return string|array
* @access private
*/
public static function parse_email($email, $only_domain = TRUE) {
sscanf($email, "%[^@]@%s", $user, $domain);
return ($only_domain) ? $domain : array($user, $domain);
}

/**
* Add an error message to the error container.
* @access protected
* @param string $msg
* @return void
*/
protected function set_error($msg) {
// Check if the error has already been encountered
if (!$this->errorEncountered) {
$this->error_count++;
$this->errorEncountered = true; // Set the flag to true to indicate error encountered
$this->ErrorInfo = $msg;
}
}

/**
* Check if an error occurred.
* @access public
* @return boolean True if an error did occur.
*/
public function isError() {
return ($this->error_count > 0);
}

/**
* Output debugging info
* Only generates output if debug output is enabled
* @see verifyEmail::$Debugoutput
* @see verifyEmail::$Debug
* @param string $str
*/
protected function edebug($str) {
if (!$this->Debug) {
return;
}
switch ($this->Debugoutput) {
case 'log':
//Don't output, just log
error_log($str);
break;
case 'html':
//Cleans up output a bit for a better looking, HTML-safe output
echo htmlentities(
preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, 'UTF-8'
)
. "<br>\n";
break;
case 'echo':
default:
//Normalize line breaks
$str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
"\n", "\n \t ", trim($str)
) . "\n";
}
}

/**
* check up e-mail
* @param string $email Email address
* @return boolean True if the valid email also exist
*/
public function check($email) {
$result = FALSE;

if (!self::validate($email)) {
$this->set_error("{$email} incorrect e-mail");
$this->edebug($this->ErrorInfo);
if ($this->exceptions) {
throw new verifyEmailException($this->ErrorInfo);
}
return FALSE;
}
$this->error_count = 0; // Reset errors
$this->stream = FALSE;

$mxs = $this->getMXrecords(self::parse_email($email));
$timeout = ceil($this->max_connection_timeout / count($mxs));
foreach ($mxs as $host) {
/**
* suppress error output from stream socket client...
* Thanks Michael.
*/
$context = stream_context_create(array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false)));
$this->stream = @stream_socket_client("ssl://{$host}:{$this->port}", $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context);

if ($this->stream === FALSE) {
if ($errno == 0) {
$this->set_error("Problem initializing the socket");
$this->edebug($this->ErrorInfo);
if ($this->exceptions) {
throw new verifyEmailException($this->ErrorInfo);
}
return FALSE;
} else {
$this->edebug($host . ":" . $errstr);
}
} else {
stream_set_timeout($this->stream, $this->stream_timeout);
stream_set_blocking($this->stream, 1);

if ($this->_streamCode($this->_streamResponse()) == '220') {
$this->edebug("Connection success {$host}");
break;
} else {
fclose($this->stream);
$this->stream = FALSE;
}
}
}

if ($this->stream === FALSE) {
$this->set_error("All connection fails");
$this->edebug($this->ErrorInfo);
if ($this->exceptions) {
throw new verifyEmailException($this->ErrorInfo);
}
return FALSE;
}

$this->_streamQuery("EHLO " . self::parse_email($this->from));
$this->_streamResponse();
$this->_streamQuery("MAIL FROM: <{$this->from}>");
$this->_streamResponse();
$this->_streamQuery("RCPT TO: <{$email}>");
$code = $this->_streamCode($this->_streamResponse());
if ($code == '250' || $code == '251') {
$result = TRUE;
} elseif ($code == '550' || $code == '551' || $code == '553' || $code == '511') {
$this->set_error("{$email} not exist");
$this->edebug($this->ErrorInfo);
}
$this->_streamQuery("RSET");
$this->_streamResponse();
$this->_streamQuery("QUIT");
fclose($this->stream);
return $result;
}

/**
* writes the contents of query to the file stream
* @access private
* @return void
*/
private function _streamQuery($query) {
$this->edebug($query);
return fwrite($this->stream, $query . self::CRLF);
}

/**
* Reads all the line long the answer and analyze the response code.
* If an error occurs, returns FALSE
* @access private
* @return string Result text
*/
private function _streamResponse($timed = 0) {
$result = '';
$start_time = time();

// Set the stream to non-blocking mode
stream_set_blocking($this->stream, 0);

while (true) {
$line = @stream_get_line($this->stream, 4096, self::CRLF);

if ($line !== FALSE) {
$result .= $line . self::CRLF;
if (isset($line[3]) && $line[3] != '-') {
break;
}
}

$status = stream_get_meta_data($this->stream);
if (!empty($status['timed_out'])) {
$this->edebug("Timed out while waiting for data! (timeout {$timed} seconds)");
return FALSE;
}

// Check if we have exceeded the read timeout
if (time() - $start_time >= $this->stream_timeout) {
$this->edebug("Stream read timeout exceeded.");
return FALSE;
}

// Sleep briefly to prevent a busy wait
usleep(100000); // 100 milliseconds
}

return $result;
}

/**
* Get Response code from Response
* @param string $str
* @return string
* @access private
*/
private function _streamCode($str) {
preg_match('/^(?<code>[0-9]{3})(\s|-)(.*)$/ims', $str, $matches);
$code = isset($matches['code']) ? $matches['code'] : false;
return $code;
}

}