当前位置: 首页 > 知识库问答 >
问题:

联系表Laravel 5.4电子邮件错误

吕宇定
2023-03-14

单击联系人表单中的“发送”按钮时出错。我使用的是Laravel 5.4。请帮我解决这个错误。

我已经清除了缓存,但仍然得到这个错误

预期响应代码250,但得到代码“530”,消息“530-5.5.1需要身份验证

这是我的邮件功能...

public function getContactUsForm(){
        $data = Input::all();
        $rules = array (
            'fullname' => 'Required',
            'email' => 'Required|Email',
            'subject' => 'Required',
            'message' => 'Required'
        );

        $validator = Validator::make ($data, $rules);
        if ($validator -> passes()){

            Mail::send('contactmail', $data, function($message) use ($data)
            {
                $message->from($data['email'] , $data['fullname']);
                $message->to('myemail', 'myname')->subject('Contact Request');

            });
            Session::put('flash_message', 'Thank you for contacting us – we will get back to you soon!');
            return redirect()->back();
        }else{
            return Redirect::to('/contactus')->withErrors($validator);
        }
    }

这是我的邮件。php文件

 <?php

return [

    /*
    |--------------------------------------------------------------------------
    | Mail Driver
    |--------------------------------------------------------------------------
    |
    | Laravel supports both SMTP and PHP's "mail" function as drivers for the
    | sending of e-mail. You may specify which one you're using throughout
    | your application here. By default, Laravel is setup for SMTP mail.
    |
    | Supported: "smtp", "sendmail", "mailgun", "mandrill", "ses",
    |            "sparkpost", "log", "array"
    |
    */

    'driver' => env('MAIL_DRIVER', 'smtp'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Address
    |--------------------------------------------------------------------------
    |
    | Here you may provide the host address of the SMTP server used by your
    | applications. A default option is provided that is compatible with
    | the Mailgun mail service which will provide reliable deliveries.
    |
    */

    'host' => env('MAIL_HOST', 'smtp.gmail.com'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Port
    |--------------------------------------------------------------------------
    |
    | This is the SMTP port used by your application to deliver e-mails to
    | users of the application. Like the host we have set this value to
    | stay compatible with the Mailgun e-mail application by default.
    |
    */

    'port' => env('MAIL_PORT', 587),

    /*
    |--------------------------------------------------------------------------
    | Global "From" Address
    |--------------------------------------------------------------------------
    |
    | You may wish for all e-mails sent by your application to be sent from
    | the same address. Here, you may specify a name and address that is
    | used globally for all e-mails that are sent by your application.
    |
    */

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'myemail'),
        'name' => env('MAIL_FROM_NAME', 'sendername'),
    ],

    /*
    |--------------------------------------------------------------------------
    | E-Mail Encryption Protocol
    |--------------------------------------------------------------------------
    |
    | Here you may specify the encryption protocol that should be used when
    | the application send e-mail messages. A sensible default using the
    | transport layer security protocol should provide great security.
    |
    */

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Server Username
    |--------------------------------------------------------------------------
    |
    | If your SMTP server requires a username for authentication, you should
    | set it here. This will get used to authenticate with your server on
    | connection. You may also set the "password" value below this one.
    |
    */

    'username' => env('myemail'),

    'password' => env('********'),

    /*
    |--------------------------------------------------------------------------
    | Sendmail System Path
    |--------------------------------------------------------------------------
    |
    | When using the "sendmail" driver to send e-mails, we will need to know
    | the path to where Sendmail lives on this server. A default path has
    | been provided here, which will work well on most of your systems.
    |
    */

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

    /*
    |--------------------------------------------------------------------------
    | Markdown Mail Settings
    |--------------------------------------------------------------------------
    |
    | If you are using Markdown based email rendering, you may configure your
    | theme and component paths here, allowing you to customize the design
    | of the emails. Or, you may simply stick with the Laravel defaults!
    |
    */

    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

共有1个答案

谷良弼
2023-03-14

您是否在中设置了电子邮件提供商。环境文件

将您的session::put更改为session::flash

更新:

在你的功能中试试这个

    public function postcontactus(Request $request) {
          $this->validate($request, array(
            'fullname' => 'Required',
            'email' => 'Required|Email',
            'subject' => 'Required',
            'messagetext' => 'Required'
          ));

          $data = array(
            'fullname' => $request->fullname,
            'email' => $request->email,
            'subject' => $request->subject,
            'messagetext' => $request->messagetext,
          );

          Mail::send('contactmail', $data, function($message) use ($data) {
            $message->from($data['email']);
            $message->to('Your Email');
            $message->subject($data['subject']);
          });
Session::put('flash_message', 'Thank you for contacting us – we will get back to you soon!');
      return redirect()->back();

    }

注意:您正在使用message以电子邮件的形式向用户传递消息,这是不允许的,因为laravel本身使用的是message方法,您应该使用我使用的另一个名称,如messagetext,或者您喜欢的任何其他名称。

还可以在刀片中更改它:

{{Form::label('messagetext', 'Message')}}
{{Form::textarea('messagetext', null, ['class'=>'form-control'])}}

. env文件设置示例:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=xxxxxxx@gmail.com
MAIL_PASSWORD=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MAIL_ENCRYPTION=ssl

让我知道它是否有效。

 类似资料:
  • 每次尝试提交此联系人表单时,都会收到以下错误消息: “请输入您的消息。” 名称错误消息和电子邮件错误消息不会出现,除非我将它们留空。我尝试在HTML中指定post。 以下是HTML: 下面是PHP:

  • 我最近开始为一家新公司工作,这家公司有一个Wordpress网站,使用Contact Form 7插件。当我们从联系人表单收到电子邮件并在Outlook中回复时,它会自动将我们自己的电子邮件地址放在回复框中(可能是从表单的“收件人”部分),而不是在表单的“发件人”部分键入问题者的电子邮件。 我想发生的是,当我回复电子邮件时,Outlook会自动将联系人7表单的“您的电子邮件”部分的电子邮件插入Ou

  • 问题内容: 我想在我正在创建的网站上使用联系表格,但是PHP不是一个选择,因为客户端不希望使用它。是否有一种聪明的方法可以解决此问题,例如发送电子邮件参数(非标准参数)或使用外部联系表?是否有一些不使用广告且可以轻松修改为其他语言的好产品? 谢谢。 问题答案: 联系人表单有数百种可嵌入(最可能基于)的解决方案,使您能够使用PHP等服务器端语言来解决问题。只是一个快速的谷歌搜索会给你一些。 或者,您

  • HTML PHP 在XAMPP服务器上运行时,我得到错误的输出,其形式为发送按钮下方的文本 显示错误输出 输入名称‘;}if(validateEmail($email)==FALSE){$EmailError.='输入有效电子邮件‘;}if(空($_POST['message'])){$EmailError.='Enter message';}}其他{$EmailError.=“您的电子邮件已成功

  • 我的网站上的联系表格有问题!我试着在网上搜索答案,但我是这个网站建设的新手,如果可能的话,我希望得到一个简单的答案。我想编码是错误的地方,但我真的不知道在哪里! 问题-我在按submit后收到电子邮件,但在我的收件箱中,它只显示主题行,不显示邮件、电子邮件或发件人的姓名。 请帮忙! 以下是HTML代码: 以及PHP代码:

  • 我正在使用spring Boot从java发送HTML电子邮件。电子邮件包括签名与我们公司的形象标志。它工作得很好。在Gmail上。但在MacOS应用程序电子邮件中,徽标是作为附件发送的,而不是内联的。 代码的非相关部分替换为...