phpmailer电子邮件发送时没有正确通过,并设置为电子邮件有一些域名

时间:2015-02-18 17:23:42

标签: php email phpmailer

我发现,如果我使用与收件人的AddAddress相同的域名的SetFrom电子邮件从我的服务器发送电子邮件,则某些收件人的电子邮件服务器会将其作为垃圾邮件防范措施退回。作为一种解决方法,每当SetFrom与AddAddress具有相同的域时,我就计划使用不同的SetFrom电子邮件。它在发送一封带有给定phpmailer对象的电子邮件时有效,但不是多个。

<?php
function getEmail($from,$to,$default='auto@mydomain.com')
{
    $from_parts=explode('@',$from);
    $to_parts=explode('@',$to);
    return($from_parts[1]==$to_parts[1]?$default:$from);
}

$user_email='john.doe@bigcompany.com';
$user_name='John Doe';
$mail = new myPHPMailer();  //Using phpmailer 5.2.9
$mail->AddReplyTo($user_email,$user_name);
$mail->Subject  = 'The Subject';
foreach($people AS $person)
{
    //If sending email to same domain, use a different email so it doesn't get bounced by some email servers.
    $mail->SetFrom(getEmail($user_email,$person['email']),$user_name);
    $mail->MsgHTML('Custom message created for each person');
    $mail->ClearAddresses();
    $mail->AddAddress($person['email'], $person['name']);
    $mail->full_name=$person['name'];
    $mail->Send();
}

?>

如果$people只包含一个人的电子邮件与发件人的域名相同,则会成功通过。我认为我不需要提供标题信息,但下面这样做仅供参考。

Received: from UUUUUA0EC08MSX.ww017.bigcompany.net (888.888.243.223) by
 UUUUUA0EC12MSX.ww017.bigcompany.net (888.888.243.227) with Microsoft SMTP Server
 (TLS) id 666.666.224.2; Wed, 18 Feb 2015 09:53:05 -0600
Received: from mail4.usa.bigcompany.com (888.888.217.110) by
 UUUUUA0EC08MSX.ww017.bigcompany.net (888.888.243.223) with Microsoft SMTP Server
 (TLS) id 666.666.224.2; Wed, 18 Feb 2015 09:53:05 -0600
Received: from goliath.bigcompany.com ([888.888.217.208])    by
 mail4.usa.bigcompany.com (8.14.4/8.14.4) with ESMTP id t1IFr4UR027082    for
 <johndoe@bigcompany.com>; Wed, 18 Feb 2015 10:53:04 -0500
Received: from hephaistos.erlm.bigcompany.de (hephaistos.bigcompany.com
 [777.777.34.77])    by goliath.bigcompany.com (8.14.4/8.14.4) with ESMTP id
 t1IFr4tT003633    (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
 verify=OK)    for <johndoe@bigcompany.com>; Wed, 18 Feb 2015 10:53:05 -0500
Received: from localhost (localhost [127.0.0.1])    by hephaistos.bigcompany.com
 (Postfix) with ESMTP id 982F320048    for <johndoe@bigcompany.com>; Wed, 18 Feb
 2015 16:53:02 +0100 (CET)
X-Spam-Flag: NO
X-Spam-Score: 0.594
X-Spam-Status: No, score=0.594 tagged_above=-999 required=8 tests=[AWL=0.002,
    BAYES_50=0.8, CTASD_SPAM_UNKNOWN=-1, EXPURGATE_CLEAN=-0.001,
    HTML_MESSAGE=0.001, MTPOLICYD_GOOD=-0.001, RDNS_NONE=0.793]
    autolearn=no
X-CTCH-RefID: str=0001.0A0D0204.54F1B55E.01B1,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0
Received: from hephaistos.bigcompany.com ([127.0.0.1])    by localhost
 (hephaistos.erlm.bigcompany.de [127.0.0.1]) (amavisd-new, port 10024)    with ESMTP
 id UbULUYtpc8qx for <johndoe@bigcompany.com>;    Wed, 18 Feb 2015 16:53:02
 +0100 (CET)
Received: from [111.111.148.75] (helo=hephaistos.bigcompany.com)    by localhost
 with ESMTP (eXpurgate 4.0.2)    (envelope-from <auto@mysite.com>)    id
 54e4b55d-a707-7f0000017549-7f000001d722-1    for <johndoe@bigcompany.com>; Wed,
 18 Feb 2015 16:53:01 +0100
X-MtScore: NO score=-5 [whitelist=-5]
Received: from smtp1.phpwebhosting.com (smtp1.phpwebhosting.com
 [111.111.148.75])    by hephaistos.bigcompany.com (Postfix) with SMTP    for
 <johndoe@bigcompany.com>; Wed, 18 Feb 2015 16:53:01 +0100 (CET)
Received: (qmail 13767 invoked from network); 18 Feb 2015 15:52:59 -0000
Received: from unknown (HELO bigcompany-pnw.sites.mysite.com)
 (outgoing@mysite.com@111.111.134.91)    by smtp1.phpwebhosting.com with
 (DHE-RSA-AES256-SHA encrypted) SMTP; Wed, 18 Feb 2015 10:52:59 -0500
Date: Wed, 18 Feb 2015 07:52:58 -0800
To: John Doe <johndoe@bigcompany.com>
From: John Doe <auto@mysite.com>
Reply-To: John Doe <johndoe@bigcompany.com>
Subject: The Subject
Message-ID: <ddbd33815b5db7e6e045abf9e050c698@bigcompany-pnw.sites.mysite.com>
X-Priority: 3
X-Mailer: PHPMailer 5.2.9 (https://github.com/PHPMailer/PHPMailer/)
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="b1_ddbd33815b5db7e6e045abf9e050c698"
Content-Transfer-Encoding: 8bit
X-purgate-ID: 149900::1454555782-0000A707-D9F7485A/0/0
X-purgate-type: clean
X-purgate-size: 949
X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de
X-purgate: clean
Return-Path: auto@mysite.com
X-MS-Exchange-Organization-AVStamp-Mailbox: SMEXtG}w;1148500;0;This mail has
 been scanned by Trend Micro ScanMail for Microsoft Exchange;
X-MS-Exchange-Organization-SCL: 0
X-MS-Exchange-Organization-AuthSource: UUUUUA0EC08MSX.ww017.bigcompany.net
X-MS-Exchange-Organization-AuthAs: Anonymous

但是,如果$people包含多个人,则电子邮件不会按预期进行,而是收件人会收到以下内容

-----Original Message-----
From: MAILER-DAEMON@smtp1.phpwebhosting.com [mailto:MAILER-DAEMON@smtp1.phpwebhosting.com]
Sent: Wednesday, February 18, 2015 7:47 AM
To: Doe, John
Subject: failure notice

Hi. This is the qmail-send program at smtp1.phpwebhosting.com.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

<johndoe@bigcompany.com>:
777.777.34.77 does not like recipient.
Remote host said: 581 5.7.1 <johndoe@bigcompany.com>: Sender address rejected: "Your e-mail could not be delivered successfully to Big Company. See CIO Intranet https://workplace.bigcompany.net/spam"
Giving up on 777.777.34.77.

--- Below this line is a copy of the message.

Return-Path: <johndoe@bigcompany.com>
Received: (qmail 30659 invoked from network); 18 Feb 2015 15:46:44 -0000
Received: from unknown (HELO bigcompany-pnw.sites.mysite.com) (outgoing@mysite.com@184.154.134.91)
        by smtp1.phpwebhosting.com with (DHE-RSA-AES256-SHA encrypted) SMTP; Wed, 18 Feb 2015 10:46:44 -0500
Date: Wed, 18 Feb 2015 07:46:42 -0800
To: John Doe <johndoe@bigcompany.com>
From: John Doe <bids@mysite.com>
Reply-To: John Doe <johndoe@bigcompany.com>
Subject: The Subject
Message-ID: <e25f7ad03dfc1b6a6beca746dcbda584@bigcompany-pnw.sites.mysite.com>
X-Priority: 3
X-Mailer: PHPMailer 5.2.9 (https://github.com/PHPMailer/PHPMailer/)
MIME-Version: 1.0
Content-Type: multipart/alternative;
        boundary="b1_e25f7ad03dfc1b6a6beca746dcbda584"
Content-Transfer-Encoding: 8bit

--b1_e25f7ad03dfc1b6a6beca746dcbda584
Content-Type: text/plain; charset=us-ascii

Custom message created for each person


--b1_e25f7ad03dfc1b6a6beca746dcbda584
Content-Type: text/html; charset=us-ascii


Custom message created for each person



--b1_e25f7ad03dfc1b6a6beca746dcbda584--

EDIT。我的电子邮件设置。

<?php
require_once ('bla/bla/PHPMailerAutoload.php');
class myPHPMailer extends PHPMailer {
    public function __construct($allow_exceptions=false){
        $email=parse_ini_file('email.ini');
        $this->isSMTP();
        $this->SMTPDebug = $email->SMTPDebug;
        $this->Debugoutput = $email->Debugoutput;
        $this->Host = $email->Host;
        $this->Port = $email->Port;
        if(isset($email->SMTPSecure)) {$this->SMTPSecure=$email->SMTPSecure;}
        $this->SMTPAuth = $email->SMTPAuth;
        $this->Username = $email->Username;
        $this->Password = $email->Password;
    }
}

[email]
SMTPDebug = 0           ;Enable SMTP debugging. 0 = off (for production use), 1 = client messages, 2 = client and server messages
Port = 587              ;Set the SMTP port number - likely to be 25, 465 or 587
Host = "smtp1.phpwebhosting.com"
Username = "outgoing@mydomain.com"
Password = "mypassword";
SMTPAuth = true
SMTPSecure = "tls"      ;devserver only sets the prefix to the servier.
Debugoutput = 'html';   ;Ask for HTML-friendly debug output

?>

0 个答案:

没有答案