Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Shane McC
Shane McC
3,005 Points

Laravel Error Message When Sending Email

I'm trying to send a basic verification email using Laravel and an account on mailgun.com. I've followed the instructions here and am getting errors. here's my code:

http://laravel.io/bin/GyqvB

public function postCreate(){
    $validator = Validator::make(Input::all(), 
        array(
            'email'             => 'required|max:50|email|unique:users',
            'username'          => 'required|alpha_dash|max:60|min:3|unique:users',
            'password'          => 'required|min:6',
            'password_again'    => 'required|same:password'
        )
    );


    if($validator->fails()){
        return Redirect::route('account-create')
                ->withErrors($validator)
                ->withInput();
    } else {

        // Create Account
        $email          = Input::get('email');
        $username       = Input::get('username');
        $password       = Input::get('password');

        // Activation Code
        $code           = str_random(60);

        $user           = User::create(array(
            'email'     => $email,
            'username'  => $username,
            'password'  => $password,
            'password'  => Hash::make($password),
            'code'      => $code,
            'active'    => 0
        ));

        if($user){
            // Send Email
            Mail::send('emails.auth.activate', array('link' => URL::route('account-activate', $code), 'username' => $username), function($message) use ($user) {
                $message->to($user->email, $user->username)->subject('Acivate Your Account');
            });

            return Redirect::route('home')
                ->with('global', 'Your account has been created. We have sent you an email to activate your account');
        }
    }

}

My Error Message Client error response [url] https://api.mailgun.net/v2/mydomain.com/messages.mime [status code] 404 [reason phrase] NOT FOUND

2 Answers

Can you show us your config/services.php and config/mail.php files?

Shane McC
Shane McC
3,005 Points

Tom Cawthorn

config/services.php return array(

/*
|--------------------------------------------------------------------------
| Third Party Services
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third party services such
| as Stripe, Mailgun, Mandrill, and others. This file provides a sane
| default location for this type of information, allowing packages
| to have a conventional place to find your various credentials.
|
*/

'mailgun' => array(
    'domain' => 'http://www.mydomainname.com',
    'secret' => 'key-mywebsitekey',
),

'mandrill' => array(
    'secret' => '',
),

'stripe' => array(
    'model'  => 'User',
    'secret' => '',
),

);

config/mail.php

return array(
'driver' => 'mailgun',

'host' => 'smtp.mailgun.org',

'port' => 587,

'from' => array('address' => 'postmaster@mg.mydomainname.com', 'name' => 'This is my website  message'),

'encryption' => 'tls',

'username' => 'postmaster@mg.mydomainname.com',

'password' => 'mypassword',

'sendmail' => '/usr/sbin/sendmail -bs',

'pretend' => false,
);

I imagine you already have done.. but just to make sure - this content here:

<?php

    'domain' => 'http://www.mydomainname.com',
    'secret' => 'key-mywebsitekey',

is replacing actual content?

Shane McC
Shane McC
3,005 Points

+Tom Cawthorn, thanks this fixed the issue.