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";