dongzhi8487 2015-02-18 17:23
浏览 53

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

I have found that if I send an email from my server using a SetFrom email with the same domain as the recipient's AddAddress, it will get bounced by some recipient's email server as a spam prevention measure. As a workaround, I planned on using a different SetFrom email whenever the SetFrom had the same domain as the the AddAddress. It works when sending one email with a given phpmailer object, but not multiple.

<?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();
}

?>

If $people just contains one person who's email has the same domain as the sender's, it successfully goes through. I don't think I need to provide the header information, but did so below for reference purposes only.

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

However, if $people contains several persons, the email doesn't go through as intended, but instead the recipient receives the following

-----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. Settings for my email.

<?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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测