PHPmailer没有提供给某些地址

时间:2017-01-31 12:13:57

标签: php phpmailer

我还有PHPmailer的另一个问题(我现在讨厌它)。问题是它只能正确地发送到一个地址,但我尝试了另外两个地址,但它不起作用。仅当“setFrom”id与“addAddress”相同时,它才有效。这是脚本:

<?php 
if (array_key_exists('email', $_POST)) {
    date_default_timezone_set('Europe/Warsaw');

require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer(true);

$mail->isSMTP();                                    
$mail->Host = 'smtp.poczta.onet.pl';
$mail->SMTPAuth = true;  
$mail->SMTPDebug = 2;                      
$mail->Username = 'myname@onet.pl'; 
$mail->Password = 'password';       
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;     

if ($mail->addReplyTo($_POST['email'])) {
    $mail->Subject = 'Wiadomość z formularza kontaktowego';
$mail->setFrom('myname@onet.pl');
$mail->addAddress('myname@onet.pl');

$mail->isHTML(false);

$mail->Body = <<<EOT
Email: {$_POST['email']}
Imię: {$_POST['name']}
Wiadomość: {$_POST['message']}
EOT;

if (!$mail->send()) {
        $msg = 'Sorry, something went wrong. Please try again later.';
} else {
        $msg = 'Message sent! Thanks for contacting us.';
}
} else {
        $msg = 'Invalid email address, message ignored.';
    }
}
?>

如果我将addAddress更改为

$mail->addAddress('myname@gmail.com');

$mail->addAddress('myname@mydomain.pl');

我什么都没收到。还

$mail->addAddress('myname@mydomain.pl');
$mail->addAddress('myname@gmail.com');
$mail->addAddress('myname@onet.pl');

也不工作。这是为什么?可能是什么问题? SMTPdebug每次都返回相同的消息,带有1个地址或3:

2017-01-31 12:09:32 SERVER -> CLIENT: 220 smtp.poczta.onet.pl ESMTP 
2017-01-31 12:09:32 CLIENT -> SERVER: EHLO dobrywebdev.pl 
2017-01-31 12:09:32 SERVER -> CLIENT: 250-smtp.poczta.onet.pl 250-PIPELINING 250-SIZE 90000000 250-ETRN 250-AUTH PLAIN LOGIN XOAUTH2 250-AUTH=PLAIN LOGIN XOAUTH2 250-ENHANCEDSTATUSCODES 250 8BITMIME 
2017-01-31 12:09:32 CLIENT -> SERVER: AUTH LOGIN 
2017-01-31 12:09:32 SERVER -> CLIENT: 334 VXNlcm5hbWU6 
2017-01-31 12:09:32 CLIENT -> SERVER: Z3JodUBvbmV0LnBs 
2017-01-31 12:09:32 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 
2017-01-31 12:09:32 CLIENT -> SERVER: R3VwaWFzem1hdGEx 
2017-01-31 12:09:32 SERVER -> CLIENT: 235 2.7.0 Authentication successful 
2017-01-31 12:09:32 CLIENT -> SERVER: MAIL FROM: 
2017-01-31 12:09:32 SERVER -> CLIENT: 250 2.1.0 Ok 
2017-01-31 12:09:32 CLIENT -> SERVER: RCPT TO: 
2017-01-31 12:09:33 SERVER -> CLIENT: 250 2.1.5 Ok 
2017-01-31 12:09:33 CLIENT -> SERVER: RCPT TO: 
2017-01-31 12:09:33 SERVER -> CLIENT: 250 2.1.5 Ok 
2017-01-31 12:09:33 CLIENT -> SERVER: RCPT TO: 
2017-01-31 12:09:34 SERVER -> CLIENT: 250 2.1.5 Ok 
2017-01-31 12:09:34 CLIENT -> SERVER: DATA 
2017-01-31 12:09:34 SERVER -> CLIENT: 354 End data with . 
2017-01-31 12:09:34 CLIENT -> SERVER: Date: Tue, 31 Jan 2017 13:09:32 +0100 
2017-01-31 12:09:34 CLIENT -> SERVER: To: xxxxx@onet.pl, xxxxx@mydomain.pl, xxxxxx@gmail.com 
2017-01-31 12:09:34 CLIENT -> SERVER: From: xxxx@onet.pl 
2017-01-31 12:09:34 CLIENT -> SERVER: Reply-To: xxxxxx@gmail.com 
2017-01-31 12:09:34 CLIENT -> SERVER: Subject: =?utf-8?Q?Wiadomo=C5=9B=C4=87_z_formularza_kontaktowego?= 
2017-01-31 12:09:34 CLIENT -> SERVER: Message-ID: <3095337e299e4acde25515b287e51756@xxxxxx.pl> 
2017-01-31 12:09:34 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.22 (https://github.com/PHPMailer/PHPMailer) 
2017-01-31 12:09:34 CLIENT -> SERVER: MIME-Version: 1.0 
2017-01-31 12:09:34 CLIENT -> SERVER: Content-Type: text/plain; charset=utf-8 
2017-01-31 12:09:34 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit 
2017-01-31 12:09:34 CLIENT -> SERVER: 
2017-01-31 12:09:34 CLIENT -> SERVER: Email: xxxxx@gmail.com 
2017-01-31 12:09:34 CLIENT -> SERVER: Imię: xxxxxxx xxxxxxxxxxxx 
2017-01-31 12:09:34 CLIENT -> SERVER: Wiadomość: Cześć 
2017-01-31 12:09:34 CLIENT -> SERVER: 
2017-01-31 12:09:34 CLIENT -> SERVER: . 
2017-01-31 12:09:34 SERVER -> CLIENT: 250 2.0.0 Ok: queued as 3vCQ6j0vswzSv6lLW 
2017-01-31 12:09:34 CLIENT -> SERVER: QUIT 
2017-01-31 12:09:34 SERVER -> CLIENT: 221 2.0.0 Bye

这可能是什么问题?我可以将所有电子邮件从该1个地址重定向到另一个地址,但我不想这样做。该服务器是否存在错误,还是应该向脚本添加内容?

1 个答案:

答案 0 :(得分:1)

  

问题是它只能正确地发送到一个地址,但我已经尝试了另外两个地址,但它不起作用。

PHPMailer只准备电子邮件内容,然后根据其配置方式,将电子邮件传递给PHP mail()函数或本地MTA(通常为sendmail)或远程SMTP服务器

无论哪种方式,电子邮件最终都会发送到处理它的SMTP服务器。如果SMTP服务器托管目标帐户,则它会存储邮件,否则会将其传递到处理收件人电子邮件地址的Internet域的SMTP服务器。

如果有些电子邮件到达目的地而其他人没有到达,那么PHPMailer就不应该受到指责。

不同的服务器对垃圾邮件有不同的策略,如果收件人的电子邮件地址有效,那么最可能的失败原因是这些服务器将您的邮件视为垃圾邮件。特别是当您尝试在短时间内发送多封电子邮件时,会发生这种情况。

您应该与您使用的SMTP服务器的系统管理员(IT人员,如果是公司服务器和/或您的ISP)讨论此问题。他们可以建议您将哪些内容放入电子邮件标题中,以增加发送电子邮件的机会。了解您的意图后,他们还可以调整SMTP和DNS服务器(SPFDKIM)的设置,以将SMTP服务器标记为合法发送电子邮件。