Проверка отправки без SMTP стандартной функцией mail
$log = mail("ВАШ-EMAIL", "Заголовок", "Текст письма \n 1-ая строчка \n 2-ая строчка \n 3-ая строчка"); echo $log;
PHP
$mhSmtpMail_Server = "mail.ВАШДОМЕН"; // smtp-сервер $mhSmtpMail_Port = "25"; // порт smtp $mhSmtpMail_Username = "ВАШ EMAIL"; $mhSmtpMail_Password = "ПАРОЛЬ ОТ ЯЩИКА"; $mhSmtpMail_log=""; // Лог отправки function MailSmtp($to, $subject, $message, $headers) { global $mhSmtpMail_Server, $mhSmtpMail_Port, $mhSmtpMail_Username, $mhSmtpMail_Password, $mhSmtpMail_log; $mhSmtpMail_localhost = "localhost"; $mhSmtpMail_newline = "\r\n"; $mhSmtpMail_timeout = "30"; $smtpConnect = fsockopen($mhSmtpMail_Server, $mhSmtpMail_Port, $errno, $errstr, $mhSmtpMail_timeout); $smtpResponse = substr(get_data($smtpConnect),0,3000); if(empty($smtpConnect)) { $output = "Failed to connect: $smtpResponse"; return $output; } else { $mhSmtpMail_log =$mhSmtpMail_log. "Connected: $smtpResponse"; } $mhSmtpMail_log = $mhSmtpMail_log. "EHLO $mhSmtpMail_localhost" . $mhSmtpMail_newline; fputs($smtpConnect, "EHLO $mhSmtpMail_localhost" . $mhSmtpMail_newline); $smtpResponse = substr(get_data($smtpConnect),0,3000); $mhSmtpMail_log = $mhSmtpMail_log.'<- '.$smtpResponse; $mhSmtpMail_log = $mhSmtpMail_log. '->'."AUTH LOGIN" . $mhSmtpMail_newline; fputs($smtpConnect,"AUTH LOGIN" . $mhSmtpMail_newline); $smtpResponse = substr(get_data($smtpConnect),0,3000); if($smtpResponse != 334) { $mhSmtpMail_log = $mhSmtpMail_log. "сервер не разрешил начать авторизацию". $mhSmtpMail_newline; fclose($smtpConnect); // echo $mhSmtpMail_log; // Вывод лога отправки exit; } $mhSmtpMail_log = $mhSmtpMail_log. '<- '.$smtpResponse; $mhSmtpMail_log = $mhSmtpMail_log. '->'.base64_encode($mhSmtpMail_Username) . $mhSmtpMail_newline; fputs($smtpConnect, base64_encode($mhSmtpMail_Username) . $mhSmtpMail_newline); $smtpResponse = substr(get_data($smtpConnect),0,3000); $mhSmtpMail_log = $mhSmtpMail_log. '<- '.$smtpResponse; $mhSmtpMail_log = $mhSmtpMail_log. '->'.base64_encode($mhSmtpMail_Password) . $mhSmtpMail_newline; fputs($smtpConnect, base64_encode($mhSmtpMail_Password) . $mhSmtpMail_newline); $smtpResponse = substr(get_data($smtpConnect),0,3000); $mhSmtpMail_log = $mhSmtpMail_log. '<- '.$smtpResponse; $mhSmtpMail_log = $mhSmtpMail_log. '->'."MAIL FROM: $mhSmtpMail_Username" . $mhSmtpMail_newline; fputs($smtpConnect, "MAIL FROM: $mhSmtpMail_Username" . $mhSmtpMail_newline); $smtpResponse = substr(get_data($smtpConnect),0,3000); $mhSmtpMail_log = $mhSmtpMail_log. '<- '.$smtpResponse; $mhSmtpMail_log = $mhSmtpMail_log. '->'."RCPT TO: $to" . $mhSmtpMail_newline; fputs($smtpConnect, "RCPT TO: $to" . $mhSmtpMail_newline); $smtpResponse = substr(get_data($smtpConnect),0,3000); $mhSmtpMail_log = $mhSmtpMail_log. '<- '.$smtpResponse; $mhSmtpMail_log = $mhSmtpMail_log. '->'."DATA" . $mhSmtpMail_newline; fputs($smtpConnect, "DATA" . $mhSmtpMail_newline); $smtpResponse = substr(get_data($smtpConnect),0,3000); $mhSmtpMail_log = $mhSmtpMail_log. '<- '.$smtpResponse; $mhSmtpMail_log = $mhSmtpMail_log. '->'."Subject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n"; fputs($smtpConnect, "Subject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n"); $smtpResponse = substr(get_data($smtpConnect),0,3000); $mhSmtpMail_log = $mhSmtpMail_log. '<- '.$smtpResponse; $mhSmtpMail_log = $mhSmtpMail_log. '->'."QUIT" . $mhSmtpMail_newline; fputs($smtpConnect,"QUIT" . $mhSmtpMail_newline); $smtpResponse = substr(get_data($smtpConnect),0,3000); $mhSmtpMail_log = $mhSmtpMail_log. '<- '.$smtpResponse; fclose($smtpConnect); } function get_data($smtp_conn) { $data=""; while($str = fgets($smtp_conn,515)) { $data .= $str; if(substr($str,3,1) == " ") { break; } } return $data; } // Заголовки $headers = "Content-type: text/html; charset=utf-8 \r\n"; $headers = $headers."From: ".$mhSmtpMail_Username; MailSmtp ('jh@ВАШДОМЕН', 'Тема письма', 'Текст письма', $headers); // echo $mhSmtpMail_log; // Вывод лога отправки
Python
import smtplib def mail(sender, sender_password, subject, message, to): smtp_server = 'smtp.ВАШДОМЕН' smtp_port = 25 smtp_pasword = sender_password mail_lib = smtplib.SMTP(smtp_server, smtp_port) mail_lib.login(sender, smtp_pasword) msg = 'From: ' + sender + '\r\nTo: ' + to + '\r\nContent-Type: text/html; charset="utf-8"\r\nSubject: ' + subject + '\r\n\r\n' msg += message mail_lib.sendmail(sender, to, msg) # отправляем письмо message = ''' Hello from Python! ''' mail('ОТПРАВИТЕЛЬ@ВАШДОМЕН', 'ПАРОЛЬ ОТ ЯЩИКА', 'Тема письма', message, 'ПОЛУЧАТЕЛЬ')