There are two fragments of the sending script almost through smtp Yandex .
The first:

<?php class SendMailSmtpClass { /** * * @var string $smtp_username - Π»ΠΎΠ³ΠΈΠ½ * @var string $smtp_password - ΠΏΠ°Ρ€ΠΎΠ»ΡŒ * @var string $smtp_host - хост * @var string $smtp_from - ΠΎΡ‚ ΠΊΠΎΠ³ΠΎ * @var integer $smtp_port - ΠΏΠΎΡ€Ρ‚ * @var string $smtp_charset - ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ° * */ public $smtp_username; public $smtp_password; public $smtp_host; public $smtp_from; public $smtp_port; public $smtp_charset; public function __construct($smtp_username, $smtp_password, $smtp_host, $smtp_from, $smtp_port = 25, $smtp_charset = "utf-8") { $this->smtp_username = $smtp_username; $this->smtp_password = $smtp_password; $this->smtp_host = $smtp_host; $this->smtp_from = $smtp_from; $this->smtp_port = $smtp_port; $this->smtp_charset = $smtp_charset; } /** * ΠžΡ‚ΠΏΡ€Π°Π²ΠΊΠ° письма * * @param string $mailTo - ΠΏΠΎΠ»ΡƒΡ‡Π°Ρ‚Π΅Π»ΡŒ письма * @param string $subject - Ρ‚Π΅ΠΌΠ° письма * @param string $message - Ρ‚Π΅Π»ΠΎ письма * @param string $headers - Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠΈ письма * * @return bool|string Π’ случаи ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠΈ Π²Π΅Ρ€Π½Π΅Ρ‚ true, ΠΈΠ½Π°Ρ‡Π΅ тСкст ошибки * */ function send($mailTo, $subject, $message, $headers) { $contentMail = "Date: " . date("D, d MYH:i:s") . " UT\r\n"; $contentMail .= 'Subject: =?' . $this->smtp_charset . '?B?' . base64_encode($subject) . "=?=\r\n"; $contentMail .= $headers . "\r\n"; $contentMail .= $message . "\r\n"; try { if(!$socket = @fsockopen($this->smtp_host, $this->smtp_port, $errorNumber, $errorDescription, 30)){ throw new Exception($errorNumber.".".$errorDescription); } if (!$this->_parseServer($socket, "220")){ throw new Exception('Connection error'); } $server_name = $_SERVER["SERVER_NAME"]; fputs($socket, "HELO $server_name\r\n"); if (!$this->_parseServer($socket, "250")) { fclose($socket); throw new Exception('Error of command sending: HELO'); } fputs($socket, "AUTH LOGIN\r\n"); if (!$this->_parseServer($socket, "334")) { fclose($socket); throw new Exception('Autorization error'); } fputs($socket, base64_encode($this->smtp_username) . "\r\n"); if (!$this->_parseServer($socket, "334")) { fclose($socket); throw new Exception('Autorization error'); } fputs($socket, base64_encode($this->smtp_password) . "\r\n"); if (!$this->_parseServer($socket, "235")) { fclose($socket); throw new Exception('Autorization error'); } fputs($socket, "MAIL FROM: <".$this->smtp_username.">\r\n"); if (!$this->_parseServer($socket, "250")) { fclose($socket); throw new Exception('Error of command sending: MAIL FROM'); } $mailTo = ltrim($mailTo, '<'); $mailTo = rtrim($mailTo, '>'); fputs($socket, "RCPT TO: <" . $mailTo . ">\r\n"); if (!$this->_parseServer($socket, "250")) { fclose($socket); throw new Exception('Error of command sending: RCPT TO'); } fputs($socket, "DATA\r\n"); if (!$this->_parseServer($socket, "354")) { fclose($socket); throw new Exception('Error of command sending: DATA'); } fputs($socket, $contentMail."\r\n.\r\n"); if (!$this->_parseServer($socket, "250")) { fclose($socket); throw new Exception("E-mail didn't sent"); } fputs($socket, "QUIT\r\n"); fclose($socket); } catch (Exception $e) { return $e->getMessage(); } return true; } private function _parseServer($socket, $response) { while (@substr($responseServer, 3, 1) != ' ') { if (!($responseServer = fgets($socket, 256))) { return false; } } if (!(substr($responseServer, 0, 3) == $response)) { return false; } return true; } } ?> 

Second:

 require_once "SendMailSmtpClass.php"; // ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅ΠΌ класс $mailSMTP = new SendMailSmtpClass('ksovreli2017@yandex.ru', 'nikusha0', 'ssl://smtp.yandex.ru', 'ksovrela', 465); // $mailSMTP = new SendMailSmtpClass('Π»ΠΎΠ³ΠΈΠ½', 'ΠΏΠ°Ρ€ΠΎΠ»ΡŒ', 'хост', 'имя отправитСля'); $headers= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=utf-8\r\n"; // ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ° письма $headers .= "From: $name <$email>\r\n"; // ΠΎΡ‚ ΠΊΠΎΠ³ΠΎ письмо $result = $mailSMTP->send($to, $tema, $text, $headers); // $result = $mailSMTP->send('ΠšΠΎΠΌΡƒ письмо', 'Π’Π΅ΠΌΠ° письма', 'ВСкст письма', 'Π—Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠΈ письма'); if($result === true){ echo "Письмо ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎ ΠΎΡ‚ΠΏΡ€Π°Π²Π»Π΅Π½ΠΎ!!!"; $date = date('dmY - H:i'); $res = mysql_query("INSERT INTO message(`to`,`name`,`email`,`title`,`text`,`login`,`date`) VALUES('$to','$name','$email','$tema','$text','$login','$date')"); echo mysql_error(); } else{ echo "ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΠ°"; } 

Yandex letters reach without problems. But on mail.ru , gmail.com and others, it is sent then no. I do not know what's the matter, help.

  • guys please, really no one came across this? - Ksovrela
  • And any errors gives? - S. Pronin
  • Error 220 and all - Ksovrela
  • And at what step does an error occur? Just answer code 220 means that you have successfully connected to the SMTP server. Perhaps the class SendMailSmtpClass should be replaced by Swiftmailer or phpmailer? - S. Pronin
  • I don’t know, but I’m definitely using this class just when I sendpulse and everything comes, probably problems with Yandex - Ksovrela

0