T
T
Trettende2018-12-13 23:42:06
PHP
Trettende, 2018-12-13 23:42:06

The From field and header processing in Yandex.Mail. How to win?

Hello.
Preamble:
There is a website (landing page), it has a submission form, it is sent by a PHP script:

Crypto code
<?php

$errorMSG = "";

// NAME
if (empty($_POST["name"])) {
    $errorMSG = "Введите Имя ";
} else {
    $name = $_POST["name"];
}

// EMAIL
if (empty($_POST["email"])) {
    $errorMSG .= "Введите Email ";
} else {
    $email = $_POST["email"];
}

// MESSAGE
if (empty($_POST["phone"])) {
    $errorMSG .= "Введите телефон ";
} else {
    $phone = $_POST["phone"];
}


$EmailTo = "[email protected]";
$Subject = "Поступила заявка с сайта";

// prepare email body text
$Body = "";
$Body .= $name;
$Body .= "\r\n";
$Body .= $phone;
$Body .= "\r\n";
$Body .= $email;
$Body .= "";

// send email
$success = mail($EmailTo, $Subject, $Body);
// redirect to success page
if ($success && $errorMSG == ""){
   echo "success";
}else{
    if($errorMSG == ""){
        echo "Something went wrong :(";
    } else {
        echo $errorMSG;
    }
}

?>


We see that $success does not contain "From: mail \r\n etc."
If the script works as it is, then mail comes to my mailbox with [email protected]
If I add "From: anything..." to $success, then [email protected] arrives
Mail lives completely on Yandex, like mail for a domain. On the hosting itself, no mails and mail domains, respectively, are registered.
Silly questions:
- What should I do with From so that I receive a letter in the Yandex mail client with a heading like: "Hello", instead of a domain mail address? I added to Contacts - it did not help. Not on PC or phone.
- Is it possible and how to change the text in From so that only "Hi" comes?
- Bonus. Is it possible to attach gravatarks to such mails?
– [email protected] only sends, but does not receive mail. I take it that's how it's supposed to be?
Help out! Thanks a lot in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Trettende, 2018-12-14
@Trettende

For those who are interested, I decided this:
For popularity, I will write that I need two mailboxes, sending (which sends form data) and receiving (the one in which you will receive mail with applications). Both are yours, both are on Yandex on the same domain (your).

spoiler code
<?php

$errorMSG = "";

$config['smtp_username'] = 'ящик отправляющий';  //ящик на яндексе
$config['smtp_port'] = '465'; // порт
$config['smtp_host'] =  'ssl://smtp.yandex.ru';  //сервер отправки
$config['smtp_password'] = 'пароль от отправляющего ящика';  //пароль
$config['smtp_debug'] = false;  //Если Вы хотите видеть сообщения ошибок, укажите true вместо false
$config['smtp_charset'] = 'utf-8';	//кодировка сообщений. (windows-1251 или utf-8, итд)
$config['smtp_from'] = 'Внимание!'; //будет показывать при прочтении в поле "От кого"
  
function smtpmail($to='', $mail_to, $subject, $message, $headers='') {
  global $config;
  $SEND =	"Date: ".date("D, d M Y H:i:s") . " UT\r\n";
  $SEND .= 'Subject: =?'.$config['smtp_charset'].'?B?'.base64_encode($subject)."=?=\r\n";
  if ($headers) $SEND .= $headers."\r\n\r\n";
  else
  {
      $SEND .= "Reply-To: ".$config['smtp_username']."\r\n";
      $SEND .= "To: \"=?".$config['smtp_charset']."?B?".base64_encode($to)."=?=\" <$mail_to>\r\n";
      $SEND .= "MIME-Version: 1.0\r\n";
      $SEND .= "Content-Type: text/html; charset=\"".$config['smtp_charset']."\"\r\n";
      $SEND .= "Content-Transfer-Encoding: 8bit\r\n";
      $SEND .= "From: \"=?".$config['smtp_charset']."?B?".base64_encode($config['smtp_from'])."=?=\" <".$config['smtp_username'].">\r\n";
      $SEND .= "X-Priority: 3\r\n\r\n";
  }
  $SEND .=  $message."\r\n";
   if( !$socket = fsockopen($config['smtp_host'], $config['smtp_port'], $errno, $errstr, 30) ) {
    if ($config['smtp_debug']) echo $errno."<br>".$errstr;
    return false;
   }
 
  if (!server_parse($socket, "220", __LINE__)) return false;
 
  fputs($socket, "HELO " . $config['smtp_host'] . "\r\n");
  if (!server_parse($socket, "250", __LINE__)) {
    if ($config['smtp_debug']) echo '<p>Не могу отправить HELO!</p>';
    fclose($socket);
    return false;
  }
  fputs($socket, "AUTH LOGIN\r\n");
  if (!server_parse($socket, "334", __LINE__)) {
    if ($config['smtp_debug']) echo '<p>Не могу найти ответ на запрос авторизаци.</p>';
    fclose($socket);
    return false;
  }
  fputs($socket, base64_encode($config['smtp_username']) . "\r\n");
  if (!server_parse($socket, "334", __LINE__)) {
    if ($config['smtp_debug']) echo '<p>Логин авторизации не был принят сервером!</p>';
    fclose($socket);
    return false;
  }
  fputs($socket, base64_encode($config['smtp_password']) . "\r\n");
  if (!server_parse($socket, "235", __LINE__)) {
    if ($config['smtp_debug']) echo '<p>Пароль не был принят сервером как верный! Ошибка авторизации!</p>';
    fclose($socket);
    return false;
  }
  fputs($socket, "MAIL FROM: <".$config['smtp_username'].">\r\n");
  if (!server_parse($socket, "250", __LINE__)) {
    if ($config['smtp_debug']) echo '<p>Не могу отправить комманду MAIL FROM: </p>';
    fclose($socket);
    return false;
  }
  fputs($socket, "RCPT TO: <" . $mail_to . ">\r\n");
 
  if (!server_parse($socket, "250", __LINE__)) {
    if ($config['smtp_debug']) echo '<p>Не могу отправить комманду RCPT TO: </p>';
    fclose($socket);
    return false;
  }
  fputs($socket, "DATA\r\n");
 
  if (!server_parse($socket, "354", __LINE__)) {
    if ($config['smtp_debug']) echo '<p>Не могу отправить комманду DATA</p>';
    fclose($socket);
    return false;
  }
  fputs($socket, $SEND."\r\n.\r\n");
 
  if (!server_parse($socket, "250", __LINE__)) {
    if ($config['smtp_debug']) echo '<p>Не смог отправить тело письма. Письмо не было отправленно!</p>';
    fclose($socket);
    return false;
  }
  fputs($socket, "QUIT\r\n");
  fclose($socket);
  return TRUE;
}

function server_parse($socket, $response, $line = __LINE__) {
  global $config;
  while (@substr($server_response, 3, 1) != ' ') {
    if (!($server_response = fgets($socket, 256))) {
      if ($config['smtp_debug']) echo "<p>Проблемы с отправкой почты!</p>$response<br>$line<br>";
 			return false;
 		}
  }
  if (!(substr($server_response, 0, 3) == $response)) {
    if ($config['smtp_debug']) echo "<p>Проблемы с отправкой почты!</p>$response<br>$line<br>";
    return false;
  }
  return true;
}

// NAME
if (empty($_POST["name"])) {
    $errorMSG = "Введите Имя ";
} else {
    $name = $_POST["name"];
}

// EMAIL
if (empty($_POST["email"])) {
    $errorMSG .= "Введите Email ";
} else {
    $email = $_POST["email"];
}

// MESSAGE
if (empty($_POST["phone"])) {
    $errorMSG .= "Введите телефон ";
} else {
    $phone = $_POST["phone"];
}


$EmailTo = "на какой ящик отправлять";
$Subject = "тема письма";

// prepare email body text
$Body = '<strong>: ';
$Body .= $name;
$Body .= $phone;
$Body .= "</strong><p>---------------<p/><p>";
$Body .= $email;
$Body .= "</p>";


$success = smtpmail($Subject, $EmailTo, 'Заявка на сайте', $Body);

// redirect to success page
if ($success && $errorMSG == ""){
   echo "success";
}else{
    if($errorMSG == ""){
        echo "Something went wrong :(";
    } else {
        echo $errorMSG;
    }
}

?>

In the HTML page we write:
spoiler code
<form id="contactForm" data-toggle="validator">
    <fieldset>
      <div class="form-group">
        <input type="text" id="name" placeholder="Ваше Имя" class="form-control" required data-error="NEW ERROR MESSAGE">
      </div>
      <div class="form-group">
        <input type="tel" id="phone" placeholder="Номер Телефона" class="form-control" required data-error="NEW ERROR MESSAGE">
      </div>
      <div class="form-group">
        <input type="email" id="email" placeholder="Действующий Email" class="form-control" required data-error="NEW ERROR MESSAGE">
      </div>
                    
      <div id="msgSubmit" class="form-message hidden"></div>
      <span class="info"><i class="fa fa-info-circle main-color" aria-hidden="true"></i> Данные не разглашаем</span>
      <button class="btn btn-default main-bg-color" type="submit" id="form-submit">ОСТАВИТЬ ЗАЯВКУ</button>
    </fieldset>
</form>

And on gravatars thus the question is closed. Yandex allows you to put your own.
I crossed my own from the i-leon website (not advertising, copyrights)

A
Abdula Magomedov, 2018-12-13
@Avarskiy

Send letters using Yandex) Via SMTP .
Use https://github.com/PHPMailer/PHPMailer
Since you already have Yandex Mail for the domain connected, create some mail ala [email protected] And through it on SMTP send letters. And in the From parameter , you can write whatever you like and all mail services will display it normally, because. mail comes from a trusted server. From Yandex.

M
Mike, 2018-12-17
@mSnus

What should I do with From so that I receive a letter in the Yandex mail client with a heading like: "Hello", instead of a domain email address?

Doesn't just specify the e-mail in angle brackets after the name not work?
From: Prive <[email protected]>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question