для яндекса работало в 2020г. так
файл init.php
файл init.php
function custom_mail($reciever, $subject, $content, $headers) {
$debug = false;
$smtp_server = 'smtp.yandex.ru'; // адрес SMTP-сервера
$smtp_port = 587; // порт SMTP-сервера
$smtp_user = 'xxxx@domen.ru'; // Имя пользователя для авторизации на SMTP-сервере
$smtp_password = 'your_password'; // Пароль для авторизации на SMTP-сервере
$mail_from = 'xxxx@domen.ru'; // Ящик, с которого отправляется письмо
if($debug){
AddMessage2Log('custom_mail');
AddMessage2Log($headers);
}
$sock = fsockopen($smtp_server,$smtp_port,$errno,$errstr,30);
$str = fgets($sock,512);
if (!$sock) {
if($debug){
AddMessage2Log("Socket is not created");
}
}
else{
smtp_msg($sock, "HELO " . $_SERVER['SERVER_NAME']);
smtp_msg($sock, "STARTTLS");
if(false == stream_socket_enable_crypto($sock, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)){
fclose($smtp); // unsure if you need to close as I haven't run into a security fail at this point
if($debug){
AddMessage2Log("unable to start tls encryption");
}
}
else{
smtp_msg($sock, "AUTH LOGIN");
smtp_msg($sock, base64_encode($smtp_user));
smtp_msg($sock, base64_encode($smtp_password));
smtp_msg($sock, "MAIL FROM: <" . $mail_from . ">");
smtp_msg($sock, "RCPT TO: <" . $reciever . ">");
smtp_msg($sock, "DATA");
$headers = "To: <".$reciever. ">\r\nSubject: " . $subject . "\r\n" . $headers;
$data = $headers . "\r\n\r\n" . $content . "\r\n.";
smtp_msg($sock, $data);
smtp_msg($sock, "QUIT");
}
}
fclose($sock);
return true;
}
function smtp_msg($sock, $msg) {
$debug = false;
if (!$sock) {
if($debug){
AddMessage2Log("Broken socket!");
}
}
else{
fputs($sock, "$msg\r\n");
$str = fgets($sock, 512);
if (!$sock) {
if($debug){
AddMessage2Log("Socket is down");
}
}
else {
$e = explode(" ", $str);
$code = array_shift($e);
$str = implode(" ", $e);
if ($code > 499) {
if($debug){
AddMessage2Log("Problems with SMTP conversation.Code Message ".$code." ".$str);
}
}
else{
if($debug){
AddMessage2Log("Code Message ".$code." ".$str);
}
}
}
}
} |