اذهب إلى المحتوى
  • 0

خطأ في إرسال الإيميلات بالgmail في لارافل

محمود موسى2

السؤال

السلام عليكم ورحمة الله وبركاته.

أحاول ارسال ايميلات بإستخدام لارافل وgmail ولكن تواجهني مشكلة 

Swift_TransportException
Connection could not be established with host smtp.gmail.io :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: No such host is known.

كود ال.env

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.io
MAIL_PORT=465
MAIL_USERNAME=mahmodreda219@gmail.com
MAIL_PASSWORD=correct_password
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=mahmodredas219@gmail.com
MAIL_FROM_NAME="${APP_NAME}"

كود الcontroller

$invoiceId = Invoices::latest()->first()->id;

$user = User::first();

Notification::send($user, new InvoiceCreation($invoiceId));

كود الnotification

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class InvoiceCreation extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    private $invoiceId;

    public function __construct($invoiceId)
    {
        $this->invoiceId = $invoiceId;
    }


    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        $url = route('invoices.show', $this->invoiceId);
        return (new MailMessage)
                    ->greeting('أهلاً!')
                    ->subject('تمت إضافة فاتورة جديدة')
                    ->line('إضافة فاتورة جديدة')
                    ->action('عرض الفاتورة', url($url))
                    ->line('شكراً لإستخدامك ' . env('APP_NAME'));
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

وقمت بالسماح للتطبيقات الأقل أماناً من google account فهل من حل؟ 

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

حاول تغيير إعدادات الإميل في ملف env :

MAIL_DRIVER=smtp    
MAIL_HOST=smtp.gmail.com   
MAIL_PORT=587      
MAIL_USERNAME=ahmodreda219@gmail.com
MAIL_PASSWORD=correct_password
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="${APP_NAME}"
MAIL_FROM_ADDRESS=mahmodredas219@gmail.com

بعد ذلك قم بإزالة cache

php artisan config:cache

أعد تشغيل الخادم المحلي الخاص بك

حاول زيارة مسارك باستخدام وحدة التحكم التي تحتوي على وظيفة البريد.

وأيضا تحتاج إلى تسجيل الدخول عبر حساب Gmail الخاص بك للسماح بالاتصال غير الموثوق به. قم بزيارة هذا الرابط للسماح بالإتصال من طرف Gmail 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • -1

كل الخطوات صحيحة و سليمة , يبدوا أن المشكلة في إستعمال سرفر smtp  .

قم بتغيير العنوان إلى :

smtp.googlemail.com

أي MAIL_HOST بملف الإعداد على هذا النحو :

MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=YOUR_EMAIL_ADDRESS
MAIL_PASSWORD=PASSWORD
MAIL_ENCRYPTION=ssl

و لا تنسى محو الكاش :

php artisan cache:clear

php artisan config:cache

 

تم التعديل في بواسطة Adnane Kadri
محو الكاش
رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...