Answer the question
In order to leave comments, you need to log in
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
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]" // почта отправителя
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question