I have a development that makes use of SwiftMailer to send Emails.
I have a Development server where it is working perfectly (with PHP 5)
And I have a production server where there is PHP 7 (and the server is very virgin, with little configuration) where it is giving these problems
The emails are sent perfectly but the mailer returns 0.
My email sending function is this:
public function sendEmail ($email) {
$transport = \Swift_MailTransport::newInstance("localhost", 25);
$mailer = \Swift_Mailer::newInstance($transport);
$message = \Swift_Message::newInstance("Recuperación de Contraseña");
if (isset($email["subject"]) && !empty($email["subject"])) {
$message->setSubject($email["subject"]);
}
if (isset($email["from"]) && !empty($email["from"])) {
$message->setFrom($email["from"]);
}
if (isset($email["to"]) && !empty($email["to"])) {
$message->setTo($email["to"]);
$message->setReadReceiptTo($email["to"]);
}
if (isset($email["embed_images"]) && !empty($email["embed_images"])) {
foreach ($email["embed_images"] as $embedImage_key=>$embedImage_value) {
if (!empty($embedImage_value)) {
$email["embed_images"][$embedImage_key] = $message->embed(\Swift_Image::fromPath($embedImage_value));
}
}
}
$email["parameters"] = array_merge($email["parameters"], array("embed_images" => $email["embed_images"]));
if (!isset($email["body"]) || empty($email["body"])) {
$message->setBody(
$this->renderView(
$email["template"],
$email["parameters"]
), 'text/html'
);
}
if (isset($email["attach_images"]) && !empty($email["attach_images"])) {
foreach ($email["attach_images"] as $attachImage_key=>$attachImage_value) {
if (!empty($attachImage_value)) {
$message->attach(Swift_Attachment::fromPath($attachImage_value));
}
}
}
$statusSend = true;
$logger = new \Swift_Plugins_Loggers_ArrayLogger;
//$logger = new \Swift_Plugins_Loggers_EchoLogger; //echo messages in real-time
$mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));
if (!$mailer->send($message, $failures)) {
$statusSend = false;
echo "Failures:";
print_r($failures);
}
echo $logger->dump(); //not needed if using EchoLogger plugin
return $statusSend;
}
And passes through
if (!$mailer->send($message, $failures)) {
Is Swift_Mailer's problem? From PHP?
Thanks