使用laravel时发送邮件时出错

时间:2016-10-09 14:26:33

标签: php laravel email

我正在建立一个可以在页面视图上向我的帐户发送邮件的网站。
我编辑了.env这样的文件:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=example@example.com
MAIL_PASSWORD=example
MAIL_ENCRYPTION=null

用户名和密码设为示例仅针对此问题,原始文件中我已提供原始姓名和电子邮件。
我的mail.php文件如下所示:

'from' => [
    'address' => 'hello@example.com',
    'name' => 'Example',
],

使用其他功能^^

MyRoute文件如下所示:

Route::get('/send', function() {
    Mail::send('email.send', ['name' => 'Its me'], function($message) {
        $message->to('example@example.com', 'Someone')->from('someone@somewhere.com')->subject('Worked');
    });
});

此处还将用户名和名称设置为示例||我只在这里,在原始文件中,我已经提供了原始名称和电子邮件。

我的email/send.blade.php文件只有{{$name}}

我使用tutorial from youtube来研究这个。

我仍然收到这样的错误

MethodNotAllowedHttpException in RouteCollection.php line 218

如何修复此错误? 请帮帮我。

2 个答案:

答案 0 :(得分:1)

  

试试这个会起作用:

Route::match(['get','post'],'/send', function() {
    Mail::send('email.send', ['name' => 'Its me'], function($message) {
        $message->to('example@example.com', 'Someone')->from('someone@somewhere.com')->subject('Worked');
    });
});

OR

 Route::any('/send', function() {
        Mail::send('email.send', ['name' => 'Its me'], function($message) {
            $message->to('example@example.com', 'Someone')->from('someone@somewhere.com')->subject('Worked');
        });
    });

答案 1 :(得分:1)

尝试!这肯定会有用

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    if (self.avplayer) {
        [self.avplayer replaceCurrentItemWithPlayerItem:nil];
    }
    AVURLAsset *avAsset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:@"http://broadcast.infomaniak.net/radionova-high.mp3"] options:nil];
    NSArray *keys = @[@"playable"];
    [avAsset loadValuesAsynchronouslyForKeys:keys completionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            AVPlayerItem *newItem = [[AVPlayerItem alloc] initWithAsset:avAsset];
            if (!self.avplayer) {
                self.avplayer = [[AVPlayer alloc] initWithPlayerItem:newItem];
            } else {
                [self.avplayer replaceCurrentItemWithPlayerItem:newItem];
            }
            [self.avplayer addObserver:self forKeyPath:@"status" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:nil];
            [self.avplayer addObserver:self forKeyPath:@"rate" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:nil];
        });
    }];

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
                        change:(NSDictionary *)change context:(void *)context {
    NSLog(@"%@ called",keyPath);
    if ( [keyPath isEqualToString:@"status"]) {
        [self.avplayer play];
    } else if ( [keyPath isEqualToString:@"rate"]) {
        if (self.avplayer.rate) {
            NSLog(@"Playing...");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"currentPlayingChangedToPlay" object:nil];

        } else {
            NSLog(@"Not playing...");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"currentPlayingChangedToPause" object:nil];
        }
    }

}
相关问题