2017-01-04 19 views
0

Я использую PHPMailer для отправки электронной почты. Письма получаются правильно, но всякий раз, когда я открываю электронную почту, которую отправил с помощью PHP Mailer, я получаю предупреждение.Получение предупреждающего сообщения после открытия электронной почты с помощью PHP

Примечание:: Если я удаляю тег привязки из $ phpMailerText, тогда я не получаю никакого предупреждения. Если я добавлю тег привязки, тогда я получаю предупреждение. Не могли бы вы мне помочь?

enter image description here

require 'mail/PHPMailerAutoload.php'; 
    $to = $email; 
    //Create a new PHPMailer instance 
    $mail = new PHPMailer; 

    //Enable SMTP debugging 
    // 0 = off (for production use) 
    // 1 = client messages 
    // 2 = client and server messages 
    $mail->SMTPDebug = 0; 

    //Ask for HTML-friendly debug output 
    $mail->Debugoutput = 'html'; 

    // Headers 
$headers = "Content-Type: text/plain; charset=\"utf-8\"\n" 
       . "X-mailer: smtp.gmail.com" . "\r\n" // this will identify the real sender 
       . "Precedence: bulk" . "\r\n" // this will say it is bulk sender 
       . "List-Unsubscribe:[email protected]\r\n" // this will reveal the OPT-OUT address 
       . "Reply-To: $to\n" 
       . "To: $to\n" 
       . "From: $to\n"; 

    //Set the hostname of the mail server 
    $mail->Host = 'smtp.gmail.com'; 

    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission 
    $mail->Port = 587; 

    //Set the encryption system to use - ssl (deprecated) or tls 
    $mail->SMTPSecure = 'tls'; 

    //Whether to use SMTP authentication 
    $mail->SMTPAuth = true; 

    //Username to use for SMTP authentication - use full email address for gmail 
    $mail->Username = "[email protected]"; 

    //Password to use for SMTP authentication 
    $mail->Password = "****"; 

    //Set who the message is to be sent from 
    $mail->setFrom('[email protected]', 'code'); 

    //Set an alternative reply-to address 
    $mail->addReplyTo('[email protected]', 'code'); 

    //Set who the message is to be sent to 
    $mail->addAddress($to, 'Customer'); 

    //Set the subject line 
    $mail->Subject = 'code'; 

    $phpMailerText="<!DOCTYPE HTML><html> 
    <head> 
    <title>HTML email</title> 
    </head> 
    <body> 

    <a href='http://www.companyname.com/changepassword.php?user_id=" .$User_id1."'>Create your password here</a> 
    </body> 
    </html>"; 

    $mail->msgHTML($phpMailerText); 

    //Replace the plain text body with one created manually 
    $mail->AltBody = ' '; 

    //send the message, check for errors 
    if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo; 
    } else { 
    } 
+0

Мы не знаем, какой компонент дает вам это предупреждение, скорее всего, какой-либо почтовый клиент или веб-приложение, которое вы используете для _read_ электронной почты? Если это так, то, скорее всего, это рейтинг SPAM. Это то, что вам нужно проверить. Откройте исходный код полученных электронных писем и проверьте, есть ли у вас заголовки, введенные механизмом обнаружения нежелательной почты. Обычно они дают подсказки о том, какие именно детали точно соответствуют рейтингу. Это хорошая отправная точка для изменения вашего сообщения. Часто это не только сам контент, но и то, как сообщение отправляется и структурируется. – arkascha

+0

Спасибо, что ответила на мистеркарша, я новичок в этом, и я об этом не знаю. –

+0

Конечно, вот почему я дал вам отправную точку. Чтобы _really_ открыть письмо, вам, как правило, нужен _real_ почтовый клиент, а не только веб-интерфейс. Хороший почтовый клиент предлагает такую ​​возможность, как «Просмотреть источник сообщения» или аналогичный. Это то, чего вы хотите. – arkascha

ответ

0

Попробуйте следующий код и сделать другие шаги.

  1. Создать обратный DNS рекорд
  2. Настройка SPF записи
$to = $email; 
//Create a new PHPMailer instance 
$mail = new PHPMailer; 

//Enable SMTP debugging 
// 0 = off (for production use) 
// 1 = client messages 
// 2 = client and server messages 
$mail->SMTPDebug = 0; 

//Ask for HTML-friendly debug output 
$mail->Debugoutput = 'html'; 

// Headers 
$headers = "Content-Type: text/plain; charset=\"utf-8\"\n" 
       . "X-mailer: YOUR_SITE_DOMAIN Server" . "\r\n" // this will identify the real sender 
       . "Precedence: bulk" . "\r\n" // this will say it is bulk sender 
       . "List-Unsubscribe:[email protected]_SITE_DOMAIN\r\n" // this will reveal the OPT-OUT address 
       . "Reply-To: $email\n" 
       . "To: $email\n" 
       . "From: $email\n"; 

$mail->addCustomHeader($headers); 

//Set the hostname of the mail server 
$mail->Host = 'smtp.gmail.com'; 

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission 
$mail->Port = 587; 

//Set the encryption system to use - ssl (deprecated) or tls 
$mail->SMTPSecure = 'tls'; 

//Whether to use SMTP authentication 
$mail->SMTPAuth = true; 

//Username to use for SMTP authentication - use full email address for gmail 
$mail->Username = "[email protected]"; 

//Password to use for SMTP authentication 
$mail->Password = "****"; 

// Because html is being used 
$mail->isHTML(true); 

//Set who the message is to be sent from 
$mail->setFrom('[email protected]', 'code'); 

//Set an alternative reply-to address 
$mail->addReplyTo('[email protected]', 'code'); 

//Set who the message is to be sent to 
$mail->addAddress($to, 'Customer'); 

//Set the subject line 
$mail->Subject = 'code'; 

$phpMailerText="<!DOCTYPE HTML><html> 
<head> 
<title>HTML email</title> 
</head> 
<body> 

<a href='http://www.companyname.com/changepassword.php?user_id=" .$User_id1."'>Create your password here</a> 
</body> 
</html>"; 

$mail->msgHTML($phpMailerText); 

//Replace the plain text body with one created manually 
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; 

//send the message, check for errors 
if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
} 
+0

Спасибо, что ответили Mr.Dean, но все же я получаю такую ​​же проблему. –

+0

Этот код только что составлен. Это просто не сработает. – Synchro

+0

Mr.Dean, я получаю ошибку Ошибка анализа: синтаксическая ошибка, неожиданный '.' в $ headers –

0

Пожалуйста, используйте следующий код и скажите мне, что будем бороться.

$mail = new PHPMailer(); // create a new object 
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only 
$mail->SMTPAuth = true; // authentication enabled 
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail 
$mail->Host = "smtp.gmail.com"; 
$mail->Port = 587; 
$mail->IsHTML(true); 
$mail->Username = "[email protected]"; 
$mail->Password = "password"; 
$mail->SetFrom("[email protected]"); 
$mail->Subject = "Test"; 
$mail->Body = "hello"; 
$mail->AddAddress("[email protected]"); 

if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message has been sent"; 
} 
+0

Mr.Dean, [email protected] и [email protected] оба письма будут одинаковыми? –

+0

Я получаю ошибку, 2017-01-04 10:47:39 SMTP УВЕДОМЛЕНИЕ: EOF пойман, проверяя, если подключено 2017-01-04 10:47:39 Ошибка SMTP connect(). Ошибка Mailer: Ошибка SMTP connect(). –

+0

Да, они будут такими же –