fonction export

Petit nouveau ! | 5 Messages

22 juil. 2009, 18:08

Bonjour,
Ci-joint une fonction (longue desolé) etant censé faire de l'export vers un mail. Cette fonction a été réalisée y a environ 1 an et aujourd'hui on doit la retravailler car notre smtp nécésite une authentification.
On a adapté pour faire un envoi avec pear. Je précise qu'un fonction mail (simple) avec pear fonctionne trés bien.
Le problème est que tous ce déroule bien mais aucun message nulle part.
Ce code etant assez complexe je voulais savoir si au moins la syntaxe etait bonne.

Merci d'avance, (désolé je n'arrive pas a "colorier" mon code)

Code : Tout sélectionner

[php]<?php class ExportMail { protected $sender, $recipient, $subject; protected $texts; protected $binary; public function __construct(&$config, $Importfile, $Importfile2) { $this->texts = $this->binary = array(); $needed_keys = array( 'sender', 'recipient', 'subject' ); foreach ($needed_keys as $key) { if (!isset($config[$key])) { Export::log("Mail :: Paramètre manquant ($key)."); die(1); } else $this->$key = $config[$key]; } } public function setText($name, $text) { $this->texts[$name] =& $text; } public function setBinary($name, $bin) { $this->binary[$name] =& $bin; } public function export() { $attach = ''; $content = ''; $boundary = md5(uniqid('BluePen-', FALSE)); $date = date('r'); $headers =<<<TXT From: <{$this->sender}> Date: $date MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="$boundary" TXT; foreach ($this->texts as $name => $value) { $content .= "\n" . $name . '=' . $value; } foreach ($this->binary as $name => $value) { if ($value === NULL) continue; $name = rawurlencode($name); $attach .= <<<MAIL --$boundary Content-Type: application/octet-stream; name="$name.png" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="$name.png" MAIL; $attach .= "\n\n".chunk_split(base64_encode($value), 70, "\n"); } mb_internal_encoding('UTF-8'); $subject = mb_encode_mimeheader($this->subject, 'UTF-8', 'B', "\n"); $message =<<<TXT Si vous voyez ce texte au lieu du contenu attendu, veuillez utiliser un client de messagerie capable d'afficher correctement les emails multipart (Outlook, Thunderbird, etc.). --$boundary Content-Type: text/plain; charset="windows-1252"; format="flowed" Content-Transfer-Encoding: 8bit $content $attach --$boundary-- TXT; // FIXME: Some MTAs require lines to end with // "\r\n" while others support only "\n". // For now, we stick to the "\r\n" style. $message = str_replace("\r", "", $message); $message = str_replace("\n", "\r\n", $message); // Under Windows, PHP speaks directly to the SMTP server, // while on Unix, the mail goes through sendmail. // Therefore, we must make sure no lone dot appears at // the beginning of a line, with respect to RFC 822. if (strpos(strtolower(PHP_OS), 'win') !== FALSE) $message = str_replace("\n.", "\n..", $message); require_once "Mail.php"; $host = "smtp.hebergeur.com"; $username = "monusername"; $password = "mdp"; /*$headers = array ( 'From' => $from, 'To' => $to, 'Subject' => $subject); */ $smtp = Mail::factory('smtp', array ( 'host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($this->recipient, $subject, $message, $headers); if (PEAR::isError($mail)) { Export::log("Mail :: Impossible d'envoyer l'email."); } else { Export::log("Mail :: Message envoyé"); } // mail($this->recipient, $subject, $message, $headers); } } ?>[/php]
[/php]

Eléphant du PHP | 453 Messages

25 juil. 2009, 00:09

Hello,

N'étant pas un pro de la mécanique, j'ai l'impression qu'il y a un soucis à propos de la syntaxe Heredoc.
La Tux attitude avec les kiw'z syou plait
Komodo Edit - Inkscape - Dia

Petit nouveau ! | 5 Messages

27 juil. 2009, 10:39

En tous cas merci d'avoir pris le temps d'avoir regarder ce code.

Heredoc, je connaisais pas mais aprés avoir regardé, c'est pas trés clair pour moi...

En tous cas, j'ai enlever le mail type Pear et j'utilise la fonction classique mail de php et la ca marche.

Merci encore

[Note : ce message a été posté de manière anonyme avant d'être réattribué à son auteur]