При отправке электронных писем с помощью PHP я всегда использовал пользовательскую функцию, которая использует STMP, и в этой функции он использует следующий заголовок, чтобы задать имя, которое, как я полагаю, вы пытаетесь установить:
"To: $nameto <$emailto>"
Где $ emailto - это фактическое электронное письмо, которое вы отправляете, а $ nameto - это то, для кого вы хотите, чтобы оно отображалось.
Вот функция, которую я использую, если вам нужно изменить какие-либо другие заголовки, которые вы можете изменить, они находятся ближе к концу функции:
/*
Desc: Used to send emails from stmp server. Make sure to have the config variables set (at the top of function). Stores logs in array, you'll need to modify the function to actually use the array though.
Params:
String $from - Email address that the email is from. Ex. "john.smith@example.com"
String $namefrom - Name to go along with the email address. Ex. "John Smith"
String $to - Email address of the recipient of the email. Ex, "jane.doe@example.com"
String $nameto - Name to go along with the email address. Ex. "Jane Doe"
String $subject - Email subject.
String $message - Main contents of email.
Return: true on success false on failure.
*/
function amail($from, $namefrom, $to, $nameto, $subject, $message)
{
$smtpServer = "";
$port = 0;
$username = "";
$password = "";
$timeout = 30;
$localhost = "127.0.0.1";
$newLine = "\r\n";
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout) or die('Could not connect.');
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect)){
return false;
} else {
$logArray['connection'] = "Connected: $smtpResponse";
}
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/plain; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;
$headers .= "Subject: $subject" . $newLine;
fputs($smtpConnect, "$headers\n\n$message\n".$newLine.".".$newLine);
$smtpResponse = fgets($smtpConnect, 1024);
$logArray['data2response'] = "$smtpResponse";
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
return true;
}