Commit fe2726cd authored by Mat's avatar Mat
Browse files

envoi de mail, parse le champs TO: nom prenom <email@domain.tld>

parent ac79ff07
......@@ -54,13 +54,12 @@ class SendMailCommand extends ContainerAwareCommand
->getRepository('PotageBundle:Lettre')
->findOneForSend(7);
$ret = $this->newsletter->sendLettreToGroup(
$lettre,
'body du mail de test'
);
$retMsg = ( $ret === 1 ) ? "\e[1;32mDone\e[0m\n" : "\e[1;31mError\e[0m\n";
$output->writeln('Sending mail .. '. $retMsg);
$retour = $this->newsletter->sendLettreToGroup($lettre,
'body du mail de test. Mail envoyé depuis la ligne de commande ');
for ($i = 0; $i < count($retour); $i++) {
$output->writeln($i .' | '. $retour[$i]['to'] .' | '. $retour[$i]['result']);
}
}
}
......@@ -22,6 +22,7 @@
<h1>Mon template twig</h1>
<h2>{{ subject }}</h2>
<h3>{{ to }}</h3>
{{ body }}
</body>
</html>
\ No newline at end of file
......@@ -21,7 +21,17 @@ class Newsletter
}
/**
* @param $to
* @param array $email
* @return string
*/
private function parseMail(array $email)
{
return $email['fullName'] .'<'. $email['email'] .'>';
}
/**
* @param array $to
* @param $subject
* @param $body
* @return int
......@@ -40,12 +50,12 @@ class Newsletter
$message = (new \Swift_Message())
->setFrom($from)
->setTo($to)
->setTo($to['email'], $to['fullName'])
->setSubject($subject)
->setBody(
$twig->render('@Potage/Mail/bodyMail.html.twig', array(
'body' => $body,
'to' => $to,
'to' => $this->parseMail($to),
'subject' => $subject
)),
'text/html'
......@@ -76,22 +86,15 @@ class Newsletter
$ret = array();
for ($i = 0; $i < count($utilisateurs); $i++)
{
//$email = array(
// $utilisateurs[$i]['email'] => $utilisateurs[$i]['prenom'] . ' ' . $utilisateurs[$i]['nom']
//);
$email = $utilisateurs[$i]['email'];
//dump($email);
$to = array(
'fullName' => $utilisateurs[$i]['prenom'] .' '. $utilisateurs[$i]['nom'],
'email' => $utilisateurs[$i]['email']
);
$ret[$i] = array(
'to' => $email,
'result' => $this->sendMail($email, $subject, $body) === 1 ? 'done' : 'error'
'to' => $this->parseMail($to),
'result' => $this->sendMail($to, $subject, $body) === 1 ? 'done' : 'error'
);
}
return $ret;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment