Answer the question
In order to leave comments, you need to log in
Why are messages from PhpMailer not logged and received?
I send emails using PhpMailer class remotely via smtp.gmail.com.
In var/log/maillog - empty, letters do not reach either.
The script itself:
<?php
function smtpmail($to, $subject, $content, $attach=false)
{
require_once('config.php'); //путь до конфигурационного файла для вашего smtp сервера
require_once('/lib/phpmailer/class.phpmailer.php'); //путь до класса phpmailer
$mail = new PHPMailer(true);
$mail->IsSMTP();
try {
$mail->Host = $__smtp['host'];
$mail->SMTPDebug = $__smtp['debug'];
$mail->SMTPAuth = $__smtp['auth'];
$mail->Port = $__smtp['port'];
$mail->Username = $__smtp['username'];
$mail->Password = $__smtp['password'];
$mail->AddReplyTo($__smtp['addreply'], $__smtp['username']);
$mail->AddAddress($to); //кому письмо
$mail->SetFrom($__smtp['addreply'], $__smtp['username']); //от кого (желательно указывать свой реальный e-mail на используемом SMTP сервере
$mail->AddReplyTo($__smtp['addreply'], $__smtp['username']);
$mail->Subject = htmlspecialchars($subject);
$mail->MsgHTML($content);
if($attach) $mail->AddAttachment($attach);
$mail->Send();
echo "Message sent Ok!</p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
}
smtpmail("[email protected]", "Zagolovok", "Content of letter", false);
?>
<?php
$__smtp = array(
"host" => "smtp.gmail.com", //smtp сервер
"debug" => 2, //отображение информации дебаггера (0 - нет вообще)
"auth" => true, //сервер требует авторизации
"port" => 465, //порт (по-умолчанию - 25)
"username" => "[email protected]",//имя пользователя на сервере
"password" => "pass",//пароль
"addreply" => "[email protected]",//ваш е-mail
"replyto" => "[email protected]" //e-mail ответа
);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question