我在使用laravel Restful API向Gmail发送电子邮件时遇到了问题,我进行了很多搜索并尝试了多种方法来解决我的问题,但是仍然有此问题并且没有解决,如果有人知道,请告诉我我该怎么做解决这个。我正在使用邮递员进行测试。
这是我的.env文件:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=ziayamin8@gmail.com
MAIL_PASSWORD=rydezigcgcjycrml
MAIL_ENCRYPTION=ssl
这是我的mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'log_channel' => env('MAIL_LOG_CHANNEL'),
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]
];
这是我的控制器功能:
public function sendmail()
{
$title = '[Confirmation] Thank you for your order';
$customer_details = ['name' => 'Zia', 'address' => 'Herat', 'phone' => '0785882156', 'email' => 'ziayamin8@gmail.com'];
$order_details = ['SKU' => 'D-123456', 'price' => '10000', 'order_date' => '2020-01-22',];
$sendmail = Mail::to($customer_details['email'])->send(new SendMail($title, $customer_details, $order_details));
if (empty($sendmail)) {
return response()->json(['message' => 'Mail Sent Sucssfully'], 200);
} else {
return response()->json(['message' => 'Mail Sent fail'], 400);
}
}
这是SendMail:
class SendMail extends Mailable
{
use Queueable, SerializesModels;
public $title;
public $customer_details;
public $order_details;
/** * Create a new message instance. * * @return void */
public function __construct($title, $customer_details, $order_details)
{
$this->title = $title;
$this->customer_details = $customer_details;
$this->order_details = $order_details;
}
/** * Build the message. * * @return $this */
public function build()
{
return $this->subject($this->title)->view('customer_mail');
}
}