OVH Community, votre nouvel espace communautaire.

Envoi de mails par php


stephaneeybert
14/03/2012, 16h55
Voila un email qui mon utilisateur a recu suite a son mailing:

(J'ai edite les veritables adresses pour ne pas les exposer)

From:
To:
Sent: Wednesday, March 14, 2012 4:49 PM
Subject: failure notice


> Hi. This is the qmail-send program at vps13495.ovh.net.
> 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.
>
> :
> 88.131.75.213 does not like recipient.
> Remote host said: 550 #5.1.0 Address rejected.
> Giving up on 88.131.75.213.
> STARTTLS proto=TLSv1; cipher=DHE-RSA-AES256-SHA;
subject=/C=HK/postalCode=111 87/ST=Hong
Kong/L=Kowloon/street=Sm\xC3\xA5landsgatan 20/O=Advokatfirman Vinge
KB/OU=Hong Kong Office/OU=Hosted by Melbourne IT Corporate Brand
Services/OU=Comodo PremiumSSL/CN=ext.vinge.com.hk; issuer=/C=GB/O=Comodo
Limited/OU=Comodo Trust Network/OU=Terms and Conditions of use:
http://www.comodo.net/repository/OU=(c)2002 Comodo Limited/CN=Comodo Class 3
Security Services CA;
>
> --- Below this line is a copy of the message.
>
> Return-Path:
> Received: (qmail 19087 invoked by uid 1002); 14 Mar 2012 11:41:20 -0000
> Message-ID: <20120314114120.19086.qmail@vps13495.ovh.net>
> To:
> Subject: Påminnelse: "Fransk afton" Onsdagen den 28 mars
> X-PHP-Originating-Script: 1002:email.php
> From: Europasprak
> Reply-To: Europasprak
> X-Sender: http://www.europasprak.com
> X-Mailer: PHP(46.105.8.54)
> X-auth-smtp-user: aaaaa.aaaaa@aaaaaaa.aaa
> Date: Wed, 14 Mar 2012 11:41:20 +0000
> MIME-Version: 1.0
> Content-Type: multipart/mixed;
> boundary="----=_NextPart_0eef849caf97199fbf4df610124c9d6a"
>
>
> ------=_NextPart_0eef849caf97199fbf4df610124c9d6a
> Content-Type: multipart/alternative;
> boundary="----=_NextPart_6532be181d5498fa1ca614f9d8c42880"
>
> ------=_NextPart_6532be181d5498fa1ca614f9d8c42880

TBC_Ly0n
14/03/2012, 16h55
Et les mails en retour disent quoi ?

stephaneeybert
14/03/2012, 16h32
Je suis sur une distribution Release 2 OVH (Gentoo) - 64 bits (English)

Dans le phpinfo:

mail.add_x_header On On
mail.force_extra_parameters no value no value
mail.log no value no value
sendmail_from no value no value
sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i
Path to sendmail /usr/sbin/sendmail -t -i

stephaneeybert
14/03/2012, 16h28
Code:
";
    $to   = "$to_name <$to_email>";

    // The text_message is displayed only if the html_message cannot be displayed
    // The text_message is a fallback message for those email clients that do not support html
    // messages
    // If the email client supports html messages and the html_message is empty then no message
    // will be displayed, that is, the text_message fallback message will not be displayed
    // To force the display of a text formatted message, store the message in the html_message
    if (!$html_message && $text_message) {
      $html_message = $text_message;
    }

    $main_boundary = "----=_NextPart_".md5(rand());
    $text_boundary = "----=_NextPart_".md5(rand());
    $html_boundary = "----=_NextPart_".md5(rand());

    $headers  = "From: $from\n";
    $headers .= "Reply-To: $from\n";
    $headers .= "Return-Path: $from\n";
    if ($confirmReception) {
      $headers .= "Disposition-Notification-To: $from\n";
      $headers .= "X-Confirm-Reading-To: $from\n";
      $headers .= "Return-Receipt-To: $from\n";
    }

    $headers .= "X-Sender: $gHomeUrl\n";
    $headers .= "X-Mailer: PHP($REMOTE_ADDR)\n";
    $headers .= "X-auth-smtp-user: $from_email\n";
// Commented out following the extensive number of bouncing emails even if these have been delivered fine
//    $headers .= "Errors-To: $from\n";
//    $headers .= "X-abuse-contact: $from\n";

//$headers.="X-AntiAbuse: Servername - {www.[caché].fr}"."\r\n";/* remplace ici par ton domaine (après le www.) */
//$headers.="X-AntiAbuse: User - [email]"."\r\n";/* mets ici ton email */
//$headers.="X-Originating-Email: [[email]]"."\r\n";/* mets ici ton email */

    $headers .= "Date: ". date('r') ."\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/mixed;\n\tboundary=\"$main_boundary\"\n";

    $message  = "\n--$main_boundary\n";
    $message .= "Content-Type: multipart/alternative;\n\tboundary=\"$text_boundary\"\n";
    $message .= "\n--$text_boundary\n";
    $message .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";
    $message .= ($text_message!="")?"$text_message":"Text portion of HTML Email";
    $message .= "\n--$text_boundary\n";
    $message .= "Content-Type: multipart/related;\n\tboundary=\"$html_boundary\"\n";
    $message .= "\n--$html_boundary\n";
    $message .= "Content-Type: text/html; charset=\"ISO-8859-1\"\n";
    $message .= "Content-Transfer-Encoding: quoted-printable\n\n";
    $message .= str_replace("=", "=3D", $html_message)."\n";

    // If the email has an html format and the attached file is an image
    // referenced in the email content then display it inline
    // otherwise display it as an attached file
    if (isset($attachedImages) && $attachedImages != '' && count($attachedImages) >= 1) {
      for ($i = 0; $i < count($attachedImages); $i++) {
        $attachedImage = $attachedImages[$i];
        $imageName = basename($attachedImage);
        if (is_file($attachedImage) && $html_message && LibImage::isImage($attachedImage) && strstr($html_message, $imageName)) {
          $fp = fopen ($attachedImage, "r");
          $fcontent = '';
          while (!feof ($fp)) {
            $fcontent .= fgets ($fp, 1024);
          }
          $fcontent = chunk_split (base64_encode($fcontent));
          fclose ($fp);
          $message .= "\n--$html_boundary\n";
          $message .= "Content-Type: image/png; name=\"$imageName\"\n";
          $message .= "Content-Transfer-Encoding: base64\n";
          $message .= "Content-Disposition: inline; filename=\"$imageName\"\n";
          $message .= "Content-ID: <$imageName>\n\n";
          $message .= $fcontent;
        }
      }
    }

    if (isset($attachedFiles) && $attachedFiles != '' && count($attachedFiles) >= 1) {
      for ($i = 0; $i < count($attachedFiles); $i++) {
        $attachedFile = $attachedFiles[$i];
        if (is_file($attachedFile)) {
          $fileName = basename($attachedFile);
          $fp = fopen ($attachedFile, "r");
          $fcontent = '';
          while (!feof ($fp)) {
            $fcontent .= fgets ($fp, 1024);
          }
          $fcontent = chunk_split (base64_encode($fcontent));
          fclose ($fp);
          $message .= "\n--$html_boundary\n";
          $message .= "Content-Type: application/octetstream\n";
          $message .= "Content-Transfer-Encoding: base64\n";
          $message .= "Content-Disposition: attachment; filename=\"$fileName\"\n";
          $message .= "Content-ID: <$fileName>\n\n";
          $message .= $fcontent;
        }
      }
    }

    $message .= "\n--$html_boundary--\n";
    $message .= "\n--$text_boundary--\n";
    $message .= "\n--$main_boundary--\n";
    mail($to, $subject, $message, $headers);
  }

}

?>

stephaneeybert
14/03/2012, 16h26
Bonjour,

Je me bat avec ma fonction d'envois de mails en php.

Mon utilisateur, lorsqu'il l'utilise pour envoyer un mailing, recoit en retour des centaines (1700 pour la derniere fois) de mails en retour.

Alors queles mails qu'il a envoyesont bien arrive me dit il.

Quelqu'un a t'il une idee ?

Merci.

Stephane