- Düzenlendi
merhabalar. laravelde mail_settings adında bir tablom var ve burada şirketler smtp bilgilerini giriyor ve girdikleri bilgiler üzerinden mail gönderme işlemini yapmak istiyorum. kuyruk yapısını da kullanmak istiyorum. mail gönderim işlemini yapmıyor. veritabanına atıyor ama mail gelmiyor.
` public function sendOfferMail(int $offer_id, string $customer_email): ServiceResponse
{
$company_id = auth()->user()->selected_company_id;
$offer = Offer::where('company_id', $company_id)->find($offer_id);
if (!$offer) {
return new ServiceResponse(false, 'Teklif bulunamadı', null, 404);
}
$mailSetting = MailSetting::where('company_id', $company_id)->first();
if (!$mailSetting) {
return new ServiceResponse(false, 'Mail ayarları bulunamadı', null, 404);
}
if (empty($mailSetting->mail_driver) ||
empty($mailSetting->mail_host) ||
empty($mailSetting->mail_port) ||
empty($mailSetting->mail_username) ||
empty($mailSetting->mail_password) ||
empty($mailSetting->mail_encryption)) {
return new ServiceResponse(false, 'Mail ayarları alanları boş bırakılamaz', null, 404);
}
try {
config(['mail.smtp.driver' => $mailSetting->mail_driver]);
config(['mail.smtp.host' => $mailSetting->mail_host]);
config(['mail.smtp.port' => $mailSetting->mail_port]);
config(['mail.smtp.username' => $mailSetting->mail_username]);
config(['mail.smtp.password' => Crypt::decryptString($mailSetting->mail_password)]);
config(['mail.smtp.encryption' => $mailSetting->mail_encryption]);
$data = [
'customer_email' => $customer_email,
'offer' => $offer
];
dispatch(new OfferMailJob($data));
//Mail::to('aydinyagiz002@gmail.com')->queue(new OfferMail($offer));
return new ServiceResponse(true, 'Teklif maili gönderildi', null, 200);
} catch (\Exception $e) {
\Log::error('Mail Gönderim Hatası: ' . $e->getMessage());
\Log::error('Mail Ayarları: ' . json_encode([
'host' => $mailSetting->mail_host,
'port' => $mailSetting->mail_port,
'username' => $mailSetting->mail_username,
'encryption' => $mailSetting->mail_encryption
]));
return new ServiceResponse(false, 'Teklif maili gönderilemedi '. $e->getMessage(), null, 500);
}
}
class OfferMailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*/
public $data;
public function __construct($data)
{
$this->data = $data;
}
/**
* Execute the job.
*/
public function handle(): void
{
Mail::to($this->data['customer_email'])->queue(new OfferMail($this->data));
}
}
class OfferMail extends Mailable
{
use Queueable, SerializesModels;
public $offer;
/**
* Create a new message instance.
*/
public function __construct($offer)
{
$this->offer = $offer;
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: 'Yeni Teklif'
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'mail.offerMail',
with: [
'offer' => $this->offer
]
);
}
<!doctype html>
<html>
<body>
<h1>Teklif Detayları</h1>
<p>Teklif UUID: {{ $offer->uuid }}</p>
<!-- Diğer teklif bilgilerini buraya ekleyebilirsiniz -->
</body>
</html>
`
` PS C:\xampp\htdocs\ays_crm> php artisan queue:work
INFO Processing jobs from the [default] queue.
2025-03-04 13:53:23 App\Jobs\OfferMailJob ..............................................................................................................................................................................
RUNNING
2025-03-04 13:53:23 App\Jobs\OfferMailJob ......................................................................................................................................................................... 38.14ms
DONE
2025-03-04 13:53:23 App\Mail\OfferMail ................................................................................................................................................................................. RUNNING
2025-03-04 13:53:23 App\Mail\OfferMail ............................................................................................................................................................................ 41.65ms FAIL
`
bu işlemi nasıl yapabilirim.