PHP中的脚本在填写表单后发送邮件

On the website of the local footballteam (enter link description here which is hosted by One.com, I programmed a soccer betting for the 8 matches of every matchday (8 matches). When the user has filled in the form and submit it, he recieves a mail with his betting and the webmaster receives a copy as Bcc. The mail is sent from the main mailbox of the domain doskobeveren.be: info@doskobeveren.be to the mail-address of the user.

Since the season 2013-2014 and the first 28 weeks of the season 2014-2015 the script has always worked fine (= 58 weeks). But since last week the Bcc part of the script gives for every mail a "Undelivered Mail Returned to Sender" in the main mailbox (info@doskobeveren.be) instead of the mailbox of the webmaster.

That mail says: Reporting-MTA: dns; mail-out2.one.com X-Postfix-Queue-ID: 9ABF0552A2 X-Postfix-Sender: rfc822; info@doskobeveren.be Arrival-Date: Wed, 15 Apr 2015 17:36:16 +0200 (CEST)

Final-Recipient: rfc822; webmaster@doskobeveren.be Original-Recipient: rfc822;webmaster@doskobeveren.be Action: failed Status: 5.7.1 Remote-MTA: dns; mxcluster2.one.com Diagnostic-Code: smtp; 550 5.7.1 Blocked by email filter

(27ec3383-e385-11e4-9d60-b82a72d88088)

The support of One.com tells me that these are the reasons:

  • Wrong Message-ID.
  • The used domainname is not correct.

Because the mail is made by the webpage, I wonder if the PHP-script causes, for wathever reason after the 58 weeks of good working, suddenly the problem?

The PHP comes from: enter link description here

enter code here
<h3>Dit bericht zal u per mail ontvangen:</h3>  
    <?php   
        $pronomail ='';
        $pronomail = $_SESSION['username']. ", u heeft de volgende pronostiek ingestuurd voor speeldag " .$speeldag. "

";

        for($i=1; $i<=8; $i++){
            $pronomail .=  "wedstrijd " .$i. ": " .$wedstrijd[$i]. " = ";
            switch ($i) {
                case 1:
                    $pronomail .= "Prono1: " .$k1w1. " - Prono2: " .$k2w1. " - Prono3: " .$k3w1. "

";
                    break;
                case 2:
                    $pronomail .= "Prono1: " .$k1w2. " - Prono2: " .$k2w2. " - Prono3: " .$k3w2. "

";
                    break;
                case 3:
                    $pronomail .= "Prono1: " .$k1w3. " - Prono2: " .$k2w3. " - Prono3: " .$k3w3. "

";
                    break;
                case 4:
                    $pronomail .= "Prono1: " .$k1w4. " - Prono2: " .$k2w4. " - Prono3: " .$k3w4. "

";
                    break;
                case 5:
                    $pronomail .= "Prono1: " .$k1w5. " - Prono2: " .$k2w5. " - Prono3: " .$k3w5. "

";
                    break;
                case 6:
                    $pronomail .= "Prono1: " .$k1w6. " - Prono2: " .$k2w6. " - Prono3: " .$k3w6. "

";
                    break;
                case 7:
                    $pronomail .= "Prono1: " .$k1w7. " - Prono2: " .$k2w7. " - Prono3: " .$k3w7. "

";
                    break;
                case 8:
                    $pronomail .= "Prono1: " .$k1w8. " - Prono2: " .$k2w8. " - Prono3: " .$k3w8. "

";
                    break;

            }

        }

        $pronomail .= " Veel succes! 

"; 
        $bericht =str_replace("
","<br />",$pronomail); 
        echo $bericht. "<br />";

        //define the receiver of the email
        $to = $_SESSION['email'];
        //define the subject of the email
        $subject = 'Pronostiek';
        //define the message to be sent. Each line should be separated with 

        $message = $pronomail;
        //define the headers we want passed. Note that they are separated with 

        $headers = "From: info@doskobeveren.be
Bcc: webmaster@doskobeveren.be
";
        $headers .= "Message-ID: <" . md5(uniqid(time())) . $_SERVER['SERVER_NAME']. ">
";
        $headers .= "MIME-Version: 1.0
";
        $headers .= "Date: ".date("D, d M Y H:i:s") . "
";
        //$headers .= "Reply-To: info@mydomain.com
";
        $headers .= "X-Priority: 3
X-MSMail-Priority: Normal
";
        $headers .= "X-Mailer: PHP/".phpversion()."
";
        $headers .= "X-MimeOLE: Produced By MyDomain
";
        $headers .= "Content-type: text/plain; charset=iso-8859-1
";         
        //$headers .= "Date: .date('r', $_SERVER['REQUEST_TIME'])
";
        //send the email
        $mail_sent = @mail( $to, $subject, $message, $headers );
        //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
        echo $mail_sent ? "Mail is verstuurd" : "Mail kon niet verstuurd worden";

?>

==========

Does someone can give me a solution please? Thanks.

The header fields are optional and really only needed if you want to custom tailor it. Comment out the line that's generating the Message-ID and it will probably pass the mail server's filtering system since it will generate a valid Message-ID itself.

I would recommend PHPMailer. It's simple and easy to implement.

<?php
require 'PHPMailerAutoload.php'; // you need to download the `PHPMailer` library and add that file path here. It changes where you place.

if(isset($_POST['submit'])
{

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = $_POST['fromAddress'];
$mail->FromName = $_POST['fromName'];
$mail->addAddress($_POST['toAddress']);               // Name is optional
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = $_POST['subject'];
$mail->Body    = $_POST['message'];

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
 }
}

?>


<html>
<body>

<form method="post" action="">
From address : <input type="email" name="fromAddress" /><br/>
From Name : <input type="text" name="fromName" /><br/>
To address :  <input type="email" name="toAddress" /><br/>
Subject : <input type="text" name="subject" /><br/>
Message : <input type="text" name="message" /><br/>
<input type="submit" name="submit" value="Submit" />

</form>

</body>
</html>

I made 1 change to my php-code:

Instaed of:

$headers = "From: info@doskobeveren.be
Bcc: webmaster@doskobeveren.be
";

I have changed it to:

$headers = "From: info@doskobeveren.be
Bcc: webmaster@lucswebsite.net
";

The mailbox:webmaster@lucswebsite.net is one of my other mailadresses. And now it worked again; there is no "Undelivered Mail Returned to Sender" mail arrived in the mailbox: info@doskobeveren.be.

So I think something has changed on the mailserver(s) of One.com that has blocked to send a Bcc between 2 mailboxes of the same domain????

I made the change suggested by Andrew Case, I commented out the line that's generating the Message-ID and changed back the Bcc to webmaster@doskobeveren.be and it works also again.