JeroenCSax
JeroenCSax

Reputation: 11

Swiftmailer breaks down after staging

I'm bringing the (Laravel-based) website for an event that's coming up soon, up to date. Part of this was improving the mailing function, for which I decided to use Mandrill's SMTP with SwiftMailer. Everything worked perfectly while working locally. However, since we pushed everything to a live (well, testing, but on the same server as live) staging area, no mails get sent anymore.

Everything seems to break down after I make a send() command in PHP. Even a simple print command doesn't do anything. There's also no errors being reported, except if I go look in my console, where the request returns a 500 Internal Server Error, without any other errors.

At the moment, these are the function I'm using only to test, which works and sends perfectly on local and then prints, but just gives a white screen on the staging area...

Route::any('test', function()
{
    testMail();
    //this print works perfectly locally but shows nothing on staging
    print ('boe');
});

function testMail(){
$to         = array('[email protected]' => 'My Name');
$subject    = 'test mail';
$text       = "test mail hier";
$htmlTekst  = "<b>boe</b><i>spaghetti</i>";
$view = View::make('mailTemplate', 
    ['naam' => 'Jeroen Cuvelier', 
    'tekst' => $htmlTekst, 
    'username' => 'my email address', 
    'password' => 99999, 
    'siteUrl' => rootUrl(), 
    'header2' => '']);
$html = $view->render();
sendEmail($text, $html, $to, $subject, "", "");}



function sendEmail($text, $html, $to, $subject, $attachment, $attachmentName)
{
    //$subject = 'Subject!';

    $from       = array('[email protected]' =>'Company event');

    /*
    SMTP-settings
    */
    $transport  = Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 25);
    $transport->setUsername('MY_MANDRILL_USERNAME');
    $transport->setPassword('MY_MANDRILL_PASSWORD');
    $swift      = Swift_Mailer::newInstance($transport);

    $message    = new Swift_Message($subject);
    $message->setFrom($from);
    $message->setBody($html, 'text/html');
    $message->setTo($to);
    $message->addPart($text, 'text/plain');

    if ($attachment != "")
    {
        $toAttach = Swift_Attachment::fromPath($attachment);
        if ($attachmentName!="")
        {
            $toAttach->setFilename($attachmentName);
        }
        $message->attach($toAttach);
    }

    //neither of these messages print on staging
    if ($recipients = $swift->send($message, $failures))
    {
     echo 'Message successfully sent!';
    } else {
     echo "There was an error:\n";
     print_r($failures);
    }
}

Upvotes: 1

Views: 76

Answers (1)

JeroenCSax
JeroenCSax

Reputation: 11

Turns out the problem was not in PHP or anything I had done. The server just didn't allow SMTP calls. A call to the company hosting that fixed my issues.

Upvotes: 0

Related Questions