From 0d92eebb6457fb694b04066a298f9da5dc8292e5 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Fri, 12 May 2017 19:42:06 +0000 Subject: [PATCH] - smtp: remove the spaces in the FROM and TO addresses (or clean the address if toto is provided git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3658 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- smtp.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/smtp.php b/smtp.php index c24b88a..57b1901 100644 --- a/smtp.php +++ b/smtp.php @@ -137,6 +137,25 @@ class smtp } } + /** Clean the provided mail and add the <> signs arround it + * @param string $mail The mail to clean + * @return string The cleaned mail + */ + private function cleanMail ($mail) + { + if (! is_string ($mail)) + throw new \Exception ("SMTP: Invalid mail provided: not a string", 500); + $mail = trim ($mail); + $pos = strpos ($mail, "<"); + if ($pos !== false) + $mail = substr ($mail, $pos); + else + $mail = "<$mail"; + if (substr ($mail, -1) !== ">") + $mail .= ">"; + return $mail; + } + /** Send the mail to the users * @param string $from The email address used for the from enveloppe * @param string|array $to the recipient of the email. Not displayed in the @@ -151,11 +170,15 @@ class smtp throw new \Exception ( _("Can't send email : not connected to SMTP server"), 500); + $from = $this->cleanMail ($from); if (is_string ($to)) $to = array ($to); $this->putLine ("MAIL FROM: $from\r\n"); foreach ($to as $t) + { + $t = $this->cleanMail ($t); $this->putLine ("RCPT TO: $t\r\n"); + } $this->putLine ("DATA\r\n"); if (substr ($completeMail, -2) !== "\r\n") $completeMail .= "\r\n";