- smtp: remove the spaces in the FROM and TO addresses (or clean the address if toto<toto@toto.com> is provided
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3658 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
23
smtp.php
23
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
|
/** Send the mail to the users
|
||||||
* @param string $from The email address used for the from enveloppe
|
* @param string $from The email address used for the from enveloppe
|
||||||
* @param string|array $to the recipient of the email. Not displayed in the
|
* @param string|array $to the recipient of the email. Not displayed in the
|
||||||
@@ -151,11 +170,15 @@ class smtp
|
|||||||
throw new \Exception (
|
throw new \Exception (
|
||||||
_("Can't send email : not connected to SMTP server"),
|
_("Can't send email : not connected to SMTP server"),
|
||||||
500);
|
500);
|
||||||
|
$from = $this->cleanMail ($from);
|
||||||
if (is_string ($to))
|
if (is_string ($to))
|
||||||
$to = array ($to);
|
$to = array ($to);
|
||||||
$this->putLine ("MAIL FROM: $from\r\n");
|
$this->putLine ("MAIL FROM: $from\r\n");
|
||||||
foreach ($to as $t)
|
foreach ($to as $t)
|
||||||
|
{
|
||||||
|
$t = $this->cleanMail ($t);
|
||||||
$this->putLine ("RCPT TO: $t\r\n");
|
$this->putLine ("RCPT TO: $t\r\n");
|
||||||
|
}
|
||||||
$this->putLine ("DATA\r\n");
|
$this->putLine ("DATA\r\n");
|
||||||
if (substr ($completeMail, -2) !== "\r\n")
|
if (substr ($completeMail, -2) !== "\r\n")
|
||||||
$completeMail .= "\r\n";
|
$completeMail .= "\r\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user