Ich bin jetzt schon seit vier Monaten in einem Projekt und bin wirklich sauer, was mit Laravel zu tun hat. Es werden keine E-Mails gesendet. Ich habe es eingerichtet, um den Mail-Treiber zu verwenden und den richtigen Code einzugeben, aber es scheint überhaupt nicht zu funktionieren. Abgesehen davon, dass es nicht funktioniert, gibt es nicht einmal einen Fehler!
Hier ist meine Konfiguration:
return array(
/*
|--------------------------------------------------------------------------
| 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", "mail", "sendmail"
|
*/
'driver' => 'mail',
/*
|--------------------------------------------------------------------------
| 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 Postmark mail service, which will provide reliable delivery.
|
*/
'Host' => 'smtp.mailgun.org',
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to delivery e-mails to
| users of your application. Like the Host we have set this value to
| stay compatible with the Postmark e-mail application by default.
|
*/
'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' => array('address' => null, 'name' => null),
/*
|--------------------------------------------------------------------------
| 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' => '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' => null,
/*
|--------------------------------------------------------------------------
| SMTP Server Password
|--------------------------------------------------------------------------
|
| Here you may set the password required by your SMTP server to send out
| messages from your application. This will be given to the server on
| connection so that the application will be able to send messages.
|
*/
'password' => null,
/*
|--------------------------------------------------------------------------
| 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',
/*
|--------------------------------------------------------------------------
| Mail "Pretend"
|--------------------------------------------------------------------------
|
| When this option is enabled, e-mail will not actually be sent over the
| web and will instead be written to your application's logs files so
| you may inspect the message. This is great for local development.
|
*/
'pretend' => false,
);
Hier ist mein PHP Code zum Versenden von E-Mails:
$data["mail_message"] = "Hello!";
Mail::send('emails.welcome', $data, function($message)
{
$message
->to('[email protected]')
->from('[email protected]')
->subject('TEST');
});
Gehen Sie zunächst in die App/config/mail.php und ändern Sie den Treiber in "Mail". Setzen Sie den Host auch als leer ein.
In meinem Szenario wurden E-Mails in die Warteschlange gestellt, weshalb ich keine Ausgabe erhielt. Ich hatte vergessen, dass ich E-Mails standardmäßig in Warteschlange eingestellt habe . Ich habe in der Jobtabelle nachgeschaut. Ich sah alle meine Nachrichten dort warten. Ich habe php artisan queue:work
ausgeführt, um die Warteschlange zum Laufen zu bringen/zu senden.
Dies kann daran liegen, dass Sie im Laravel-Projektstamm eine ".env" -Datei mit folgender Mail-Server-Konfiguration haben:
...
MAIL_DRIVER=mail
MAIL_Host=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Es scheint, dass die ".env" -Datei die "config/mail.php" -Datei überschreibt. Sie können einfach die gleichen Zeilen aus der Datei ".env" entfernen, um die Konfigurationsoptionen "config/mail.php" zu verwenden.
Gehe zur .env-Datei und setze
MAIL_DRIVER=smtp
Oder Sie können den Treiber über die Konfigurationsdateien einstellen. Wechseln Sie in die Datei Laravel 4: app/config/mail.php Laravel 5: config/mail.php .__
'driver' => 'smtp',
Sie können SMTP verwenden. Hoffe es wird helfen.
Eine Lösung für Benachrichtigungen, die nicht per E-Mail gesendet werden
https://laravel.com/docs/5.7/notifications#customizing-the-recipient
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* Route notifications for the mail channel.
*
* @param \Illuminate\Notifications\Notification $notification
* @return string
*/
public function routeNotificationForMail($notification)
{
return $this->email_address;
}
}
zuerst müssen Sie Ihre Konfigurationsdatei bearbeiten MAIL_DRIVER = smtp MAIL_Host = smtp.gmail.com MAIL_PORT = 587 [email protected]l.com MAIL_PASSWORD = xxxxxxxxxx MAIL_ENCRYPTION = tls
der run-Befehl: PHP-Handwerker make: Mail-Name
public function build (Request $ request) {return $ this-> view ('mail [' variable '=> $ request-> message]) -> an ($ request-> to);}
webdatei
Route :: post ('send', 'mailController @ send'); Route :: get ('email', 'mailController @ email');
ihre Controller-Datei
öffentliche Funktion send () {Mail :: send (neuer Name ());} öffentliche Funktion email () {return view ('email');}
ansicht: E-Mail
ansicht: Mail
oder wenn Sie möchten, dass die Website weitere Details gestaltet
https://codingexpertise.blogspot.com/2018/12/wie-nach-senden-mail-in-laravel.htmlhttps://codingexpertise.blogspot.com/2018/11/ laravel-new.html
Die Korrektur, die für mich funktionierte
.env
-Datei APP_URL=127.0.01
in APP_URL=http://localhost
.config:cache
aus, und starten Sie den Server neu.Danach begann meine Mail zu senden!
Wie ich zu diesem Fix gekommen bin
Ich hatte meine SMTP-Details zuvor richtig eingerichtet, aber selbst nachdem Sie config: cache config: gelöscht und meinen Server neu gestartet hatten, wurden die E-Mails nicht gesendet. Danach verglich ich es mit meiner Laravel App und der einzige Unterschied war 127.0.0.1 -> http: // localhost , also habe ich das als letzten Grabenversuch geändert und es hat funktioniert.
Ich habe es endlich geschafft. Wenn Sie Mailgun verwenden, fügen Sie diese Informationen unten in Ihre .env
-Datei ein
MAILGUN_DOMAIN=your.mailgundomain.com
MAILGUN_SECRET=key-yourmailgunkey
und dann rennen
php artisan config:clear
Ändern Sie den Treiber in Ihrer Konfigurationsdatei von 'Mail' in 'smtp'. Ich denke, das sollte funktionieren.