简体   繁体   English

使用形式和多个地址在Laravel中发送电子邮件

[英]Sending email in Laravel with form and with multiple addresses

my focus is to send an email with a form where you can insert: name, last name, from(any email), to (my email). 我的重点是发送带有以下格式的电子邮件:您可以在其中插入:姓名,姓氏,从(任何电子邮件)到(我的电子邮件)。 First of all I have tried using the google configuration(see on internet), but the email don't send, the result is a blank page. 首先,我尝试使用google配置(请参见Internet),但是电子邮件未发送,结果是空白页。 I must configuration only services.php and .env ? 我必须仅配置services.php和.env吗?

Nothing too complicated, have you read the docs ? 没什么复杂的,您阅读过文档吗?

First of all you need to setup your configuration inside config/mail.php (as 'driver' ) or in your .env (as MAIL_DRIVER ). 首先,您需要在config/mail.php (作为'driver' )或.env (作为MAIL_DRIVER )中设置配置。

You may start setting it to sendmail , but consider using smtp or a service like mailgun as soon as you go online. 您可以开始将其设置为sendmail ,但是请考虑在上网后立即使用smtp或mailgun之类的服务。

Second step is the creation of a view, as example in app/resources/views/emails (the snippet that follows would use app/resources/views/emails/reminder.blade.php ), however you can name it whatever you prefer. 第二步是创建视图,例如在app/resources/views/emails (后面的代码段将使用app/resources/views/emails/reminder.blade.php ),但是您可以随意命名。

Then in your controller all you have to do is just: 然后,在您的控制器中,您要做的只是:

$email = 'email@foo.bar';
$name  = 'John Doe';

Mail::send('emails.reminder', [], function ($m) {
    $m->from('hello@app.com', 'Your Application');
    $m->to($email, $name)->subject('Your Reminder!');
});

Where the array passed as second argument may contain additional data that you may want to pass to the view. 作为第二个参数传递的数组可能包含您可能希望传递给视图的其他数据。

// EDIT Sorry, I didn't understand you meant to use gmail. //编辑对不起,我不明白您打算使用gmail。

In that case you may need to configure smtp settings. 在这种情况下,您可能需要配置smtp设置。 As an example, if you would use .env for settings it should reflect something like: 例如,如果使用.env进行设置,则应反映如下内容:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=mybeautifulpasswordthatnooneknows
MAIL_ENCRYPTION=tls

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM