public function send(Message $mail)
{
$mail = clone $mail;
try {
if (!$this->connection) {
$this->connect();
}
if (($from = $mail->getHeader('Return-Path')) || ($from = key($mail->getHeader('From')))) {
$this->write("MAIL FROM:<{$from}>", 250);
}
foreach (array_merge((array) $mail->getHeader('To'), (array) $mail->getHeader('Cc'), (array) $mail->getHeader('Bcc')) as $email => $name) {
$this->write("RCPT TO:<{$email}>", [250, 251]);
}
$mail->setHeader('Bcc', NULL);
$data = $mail->generateMessage();
$this->write('DATA', 354);
$data = preg_replace('#^\\.#m', '..', $data);
$this->write($data);
$this->write('.', 250);
if (!$this->persistent) {
$this->write('QUIT', 221);
$this->disconnect();
}
} catch (SmtpException $e) {
if ($this->connection) {
$this->disconnect();
}
throw $e;
}
}