Я пытался использовать Pear Mail с SMTP, поэтому я изменил код, как показано ниже. Тем не менее, почта не получила отправки, и когда я отправляю ее, "заголовки $ должны быть массивом". Где я ошибся с кодами?
$today = date("Y-m-d H:i:s");
$data = $ip . ' ' . $today . PHP_EOL;
require_once "Mail.php";
$host = "146.168.8.237";
$port = "25";
$subject = "A Card from {$ayname}";
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port,'auth' => false));
$headers = array ('From' => $aymail,'To' => $recipent,'Subject' => $subject);
$headers = "From: {$ayname}<{$aymail}>\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=utf-8";
$recipients = explode(",", $arsemail);
$amsg11=addslashes($amsg);
foreach($recipients as $recipient){
mysql_query('INSERT INTO 'contact' ('id','ip_address','recipient_email','your_email', 'message','date') VALUES (NULL,"'.$ip.'","'.$recipient.'","'.$aymail.'","'.$amsg11.'","'.$today.'")');
$mail = $smtp->send($recipient , $subject , $mailbody, $headers);
У вас есть следующий код, и я думаю, что ошибка должна быть во второй, просто удалите вторую строку, чтобы лучше удалить или прокомментировать вторую строку
$headers = array ('From' => $aymail,'To' => $recipent,'Subject' => $subject);
$headers = "From: {$ayname}<{$aymail}>\r\n" . "MIME-Version: 1.0\r\n" ....
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$message = new Mail_mime($crlf);
$message->setTXTBody($body);
$message->setHTMLBody($body_html);
$body = $message->get();
$headers = $message->headers($headers);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'port' => xxx,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
Полная рабочая функция не забудьте указать файл Mail
function doEmail($to, $message $subject, $name){
$from = "Administrator <[email protected]>";
$reply_email = "[email protected]";
$to = "$name <$to>";
$subject = $subject;
$body = strip_tags($m);
$body_html = $m;
$crlf = "\n";
$host = "localhost";
$username = "";
$password = "";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject,
'Reply-To' => $reply_email,
'Return-path' => $reply_email,
'Content-Type' => "text/html; charset=utf-8");
$message = new Mail_mime($crlf);
$message->setTXTBody($body);
$message->setHTMLBody($body_html);
$body = $message->get();
$headers = $message->headers($headers);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => false,
'username' => '',
'password' => ''));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
} else {
}
}