【问题标题】:Laravel 5 mail doesn't workLaravel 5 邮件不起作用
【发布时间】:2015-12-02 10:57:36
【问题描述】:

我现在正在使用 Laravel 5.1,由于某种原因,我的代码,即使你看起来不错,也不能正常工作。

我正在尝试让我的应用程序发送一封电子邮件,其中包含一个视图作为消息。

public function sale(Request $request, $id)
{

    $laptops = Laptops::findOrFail($id);

    $name = Input::get('usr');
    $lname = Input::get('lname');
    $email = Input::get('email');
    $city = Input::get('city');
    $street = Input::get('street');
    $houseNr = Input::get('houseNr');
    $postCode = Input::get('postCode');
    $telephone = Input::get('telephone');
    $dCity = Input::get('deliveryCity');
    $dStreet = Input::get('deliveryStreet');
    $dHouseNr = Input::get('deliveryHouseNr');
    $dPostCode = Input::get('deliveryPostCode');
    $dTelephone = Input::get('deliveryTelephone');



    DB::table('orders')->insert([
    [
        'customerName' => Input::get('usr'),
        'customerLastname' => Input::get('lname'),
        'customerEmail' => Input::get('email'),
        'customerCity' => Input::get('city'),
        'customerStreet' => Input::get('street'),
        'customerHomeNumber' => Input::get('houseNr'),
        'customerPostNumber' => Input::get('postCode'),
        'customerPhoneNumber' => Input::get('telephone'),
        'customerDeliveryCity' => Input::get('deliveryCity'),
        'customerDeliveryStreet' => Input::get('deliveryStreet'),
        'customerDeliveryHomeNumber' => Input::get('deliveryHouseNr'),
        'customerDeliveryPostNumber' => Input::get('deliveryPostCode'),
        'customerDeliveryPhoneNumber' => Input::get('deliveryTelephone'),
        'choosenNotebook' => $laptops->name,
        'choosenGpu' => $laptops->gpu,
        'choosenCpu' => $laptops->cpu,
        'choosenRam' => $laptops->ram,
        'choosenHdd' => $laptops->hdd,
        'choosenSsd' => $laptops->ssd,
        'choosenAHdd' => $laptops->hdd2,
        'choosenASsd' => $laptops->ssd2,
        'choosenOs' => $laptops->os,
        'choosenWarranty' => $laptops->warrantyOption,
        'orderPrice' => $laptops->price,
    ]]);


    Mail::send('shop.message', ['name' => Input::get('usr'), 'lastname' => Input::get('lname')], function($message)
    {

        $message->to(Input::get('email'), Input::get('usr'))->from('support@dreammachines.pl')->subject('Informacje dotyczące sprzędaży.');

    });

    return view('shop.payment', compact('laptops', 'name', 'lname', 'email', 'city', 'street', 'houseNr', 'postCode', 'telephone', 'dCity', 'dStreet', 'dHouseNr', 'dPostCode', 'dTelephone'));

}

这就是我的控制器看起来正确的样子,它基本上从输入中获取数据并从数据库中获取一些其他信息,然后它应该将该数据保存在其他表中,(这将用于跟踪一些应用程序的信息)。之后它应该发送一条消息,但即使你我的.env 文件设置正确,我也没有收到任何电子邮件。其余代码按我的意愿工作。

知道什么可能导致此脚本无法正常工作吗?

【问题讨论】:

  • 根据您发布的内容,我们无法确定 哪个 服务正在用于发送电子邮件。是 PHP 的 mail (这取决于在本地安装后缀)还是像 Mailgun 这样的服务。
  • 首先要检查的始终是应用程序日志。您是使用本地驱动程序(例如 sendmail)发送,还是调用一些 API,例如 Mailgun?如果是第一个,请检查邮件日志——通常是/var/log/mail.log——以确保应用程序甚至尝试发送邮件。如果使用 API,请检查他们的日志,尝试通过 curl 手动发送邮件,看看会发生什么。
  • 能否请您发布错误获取。
  • 我使用的服务是'Illuminate\Support\Facades\Mail;',至于驱动它只是一个smtp。没有错误显示。除了那些没有发送的邮件之外,一切都运行良好。我之前一直在尝试使用 SendMail,但它在 Windows 上对我来说似乎效果不佳。
  • 首先检查 Laravel 日志文件。还要检查pretend是否在邮件配置下设置为true

标签: php email laravel-5 laravel-facade


【解决方案1】:

使用PHPMailer,如果你在本地做它不会工作。PHPMailer会配置你的php.ini文件,然后你一定会收到邮件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 2015-03-20
    • 2014-04-07
    • 2017-07-28
    • 2016-01-30
    相关资源
    最近更新 更多