简体   繁体   中英

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. I must configuration only services.php and .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 ).

You may start setting it to sendmail , but consider using smtp or a service like mailgun as soon as you go online.

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.

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.

In that case you may need to configure smtp settings. As an example, if you would use .env for settings it should reflect something like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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