doubiankang2845 2017-02-09 11:52
浏览 87

Symfony 3 - Swift_Mailer - 发送电子邮件但输入失败并返回0

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ogg dd trandata 报错
    • ¥15 高缺失率数据如何选择填充方式
    • ¥50 potsgresql15备份问题
    • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
    • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
    • ¥60 pb数据库修改与连接
    • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
    • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
    • ¥20 神经网络Sequential name=sequential, built=False
    • ¥16 Qphython 用xlrd读取excel报错