A
A
Andrey Terentiev2018-12-06 14:10:50
Email
Andrey Terentiev, 2018-12-06 14:10:50

How to implement dynamic "To" headers in email via SMTP?

Hello. A question.
I am writing a script for sending applications to several mailboxes via the Yandex SMTP server. The script as a whole functions normally, but in the heading "to:" or "To:" the address for whom the letter is intended is not displayed.
Tell me how to make a dynamic substitution of the To header from the foreach loop.
Actually the code itself:

<?php

require_once "SendMailSmtpClass.php"; // подключаем класс
 
$mailSMTP = new SendMailSmtpClass('[email protected]', 'xxxxxxxx', 'ssl://smtp.yandex.ru', 'Андрей', 465);

 /* Здесь проверяется существование переменных */
 if (isset($_POST['name'])) {$name = $_POST['name'];}
 if (isset($_POST['phone'])) {$phone = $_POST['phone'];}
 if (isset($_POST['email'])) {$email = $_POST['email'];}
  

/* А здесь прописывается текст сообщения, \n - перенос строки */
 $mes = "Тема: Заказ звонка!\nИмя: $name\nТелефон: $phone\nEmail: $email";

$sub='Заказ с сайта'; //сабж subject предмет, тема 

// заголовок письма
$headers= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n"; // кодировка письма
$headers .= "From: Андрей <[email protected]>\r\n"; // от кого письмо
$headers .= "To: <$nam>\r\n"; // кому письмо

  
  $names = array("[email protected]", "[email protected]");
   foreach ($names as $nam){
     $result =  $mailSMTP->send($nam, $sub, $mes, $headers); // отправляем письмо
   }
  
ini_set('short_open_tag', 'On');
header('Refresh: 0; URL=/ok');
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
akelsey, 2018-12-09
@akelsey

According to the official documentation , the fourth parameter in the send command is "@param string $smtp_from - sender. Array with name and e-mail" of the form

$from = array(
    "Евгений", // Имя отправителя
    "[email protected]" // почта отправителя
);

And you're trying to feed him hiders...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question