Wrote a module for sending emails via gmail to SMTP. Half a year worked fine, there were no problems. That that has ceased to work, returns an error 501

Ошибка: 5.5.4 HELO/EHLO argument ssl://smtp.gmail.com invalid, closing connection. e25sm23107227wmi.21 - gsmtp вмСсто 250 62 

Tell me, what could happen that stopped all work?

More: A piece of text to send:

 $sendMail = new sendMail("******@gmail.com", "******", 465, "ssl://smtp.gmail.com", "utf-8", "Error Reporting"); $sendMail->From('Error Reporting'); $sendMail->To('******@gmail.com'); $sendMail->Subject('Error Reporting'); $message = 'test test test'; 

send class itself:

 <?php class sendMail{ private $username = false; private $password = false; private $port = false; private $host = false; private $charset = false; private $from = false; private $debug = false; private $_from = ''; private $_to = ''; private $_subject = ''; private $_send = ''; private $_message = ''; public function __construct($username, $password, $port, $host, $charset, $from) { $this->username = $username; $this->password = $password; $this->port = $port; $this->host = $host; $this->charset = $charset; $this->from = $from; $this->debug = true; } public function From($name){ $this->_from = "From: " . '=?utf-8?B?'.base64_encode($name).'?=' . " <" . $this->username . ">"; } public function To($email){ $this->_to = $email; } public function Subject($subject){ $this->_subject = $subject; } public function Message($message){ $this->_message = $message; } public function smtpmail(){ $this->_send .= "Date: ".date("D, d MYH:i:s") . " UT\r\n"; $this->_send .= "Subject: =?" . $this->charset .'?B?' . base64_encode($this->_subject) . "=?=\r\n"; $this->_send .= 'Content-type: text/html; charset="' . $this->charset .'"' . "\r\n"; $this->_send .= $this->_from."\r\n"; $this->_send .= "To: '" . $this->_to . "'<" . $this->_to . ">"."\r\n"; $this->_send .= "X-Priority: 3\r\n\r\n"; $this->_send .= $this->_message."\r\n"; if( !$socket = fsockopen($this->host, $this->port, $errno, $errstr, 30) ) { if ($this->debug) echo $errno."&lt;br&gt;".$errstr; return false; } if (!$this->server_parse($socket, "220", __LINE__)) return false; fputs($socket, "EHLO " . $this->host . "\r\n"); if (!$this->server_parse($socket, "250", __LINE__)) { if ($this->debug) echo '<p>НС ΠΌΠΎΠ³Ρƒ ΠΎΡ‚ΠΏΡ€Π°Π²ΠΈΡ‚ΡŒ HELO!</p>'; fclose($socket); return false; } fputs($socket, "AUTH LOGIN\r\n"); if (!$this->server_parse($socket, "334", __LINE__)) { if ($this->debug) echo '<center><p>НС ΠΌΠΎΠ³Ρƒ Π½Π°ΠΉΡ‚ΠΈ ΠΎΡ‚Π²Π΅Ρ‚ Π½Π° запрос Π°Π²Ρ‚ΠΎΡ€ΠΈΠ·Π°Ρ†ΠΈ.</p></center>'; fclose($socket); return false; } fputs($socket, base64_encode($this->username) . "\r\n"); if (!$this->server_parse($socket, "334", __LINE__)) { if ($this->debug) echo '<center><p>Π›ΠΎΠ³ΠΈΠ½ Π°Π²Ρ‚ΠΎΡ€ΠΈΠ·Π°Ρ†ΠΈΠΈ Π½Π΅ Π±Ρ‹Π» принят сСрвСром!</p></center>'; fclose($socket); return false; } fputs($socket, base64_encode($this->password) . "\r\n"); if (!$this->server_parse($socket, "235", __LINE__)) { if ($this->debug) echo '<center><p>ΠŸΠ°Ρ€ΠΎΠ»ΡŒ Π½Π΅ Π±Ρ‹Π» принят сСрвСром ΠΊΠ°ΠΊ Π²Π΅Ρ€Π½Ρ‹ΠΉ! Ошибка Π°Π²Ρ‚ΠΎΡ€ΠΈΠ·Π°Ρ†ΠΈΠΈ!</p></center>'; fclose($socket); return false; } fputs($socket, "MAIL FROM: <".$this->username.">\r\n"); if (!$this->server_parse($socket, "250", __LINE__)) { if ($this->debug) echo '<center><p>НС ΠΌΠΎΠ³Ρƒ ΠΎΡ‚ΠΏΡ€Π°Π²ΠΈΡ‚ΡŒ ΠΊΠΎΠΌΠΌΠ°Π½Π΄Ρƒ MAIL FROM: </p></center>'; fclose($socket); return false; } fputs($socket, "RCPT TO: <" . $this->_to . ">\r\n"); if (!$this->server_parse($socket, "250", __LINE__)) { if ($this->debug) echo '<center><p>НС ΠΌΠΎΠ³Ρƒ ΠΎΡ‚ΠΏΡ€Π°Π²ΠΈΡ‚ΡŒ ΠΊΠΎΠΌΠΌΠ°Π½Π΄Ρƒ RCPT TO: </p></center>'; fclose($socket); return false; } fputs($socket, "DATA\r\n"); if (!$this->server_parse($socket, "354", __LINE__)) { if ($this->debug) echo '<center><p>НС ΠΌΠΎΠ³Ρƒ ΠΎΡ‚ΠΏΡ€Π°Π²ΠΈΡ‚ΡŒ ΠΊΠΎΠΌΠΌΠ°Π½Π΄Ρƒ DATA</p></center>'; fclose($socket); return false; } fputs($socket, $this->_send ."\r\n.\r\n"); if (!$this->server_parse($socket, "250", __LINE__)) { if ($this->debug) echo '<center><p>НС смог ΠΎΡ‚ΠΏΡ€Π°Π²ΠΈΡ‚ΡŒ Ρ‚Π΅Π»ΠΎ письма. Письмо Π½Π΅ Π±Ρ‹Π»ΠΎ ΠΎΡ‚ΠΏΡ€Π°Π²Π»Π΅Π½Π½ΠΎ!</p></center>'; fclose($socket); return false; } fputs($socket, "QUIT\r\n"); fclose($socket); return TRUE; } private function server_parse($socket, $response, $line = __LINE__) { while (@substr($server_response, 3, 1) != ' ') { if (!($server_response = fgets($socket, 256))) { if ($this->debug) echo "<p>Problems sending mail!</p>$response<br>$line<br>"; return false; } } if (substr($server_response, 0, 3) != $response) { if ($this->debug) echo "<p>Problems sending mail!</p>$server_response вмСсто $response<br>$line<br>"; return false; } return true; } } 
  • Faced the same problem. Check that you have sent to EHLO. With EHLO smtp.gmail.com should work. - user3715865
  • I threw off all my code, EHLO. With EHLO smtp.gmail.com does not work, maybe I didn’t understand something, please explain - Ivan Turcan

1 answer 1

Google recently made a change to the terms of message delivery. The connection is rejected if the HELO / EHLO arguments are not specified or are invalid. If the server data is invalid (for example, a domain name), the message is rejected or returned.

Reference article