{
"isSuccess": false,
"message": "Teklif maili gönderilemedi Method Illuminate\\Mail\\Mailer::build does not exist.",
"data": null,
"statusCode": 500
}
böyle bir hata alıyorum hocam. laravel 10 kullanıyorum. ayrıca Job dosyasını iptal etmek istiyorum. Yada etmek mantıklı mı. zaten mail dosyam var bir de job dosyası eklemeyeyim diye düşündüm. direkt mail dosyasıyla işlem yapmak istiyorum.
`
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 {
Mail::build([
'transport' => $mailSetting->mail_driver,
'host' => $mailSetting->mail_host,
'port' => $mailSetting->mail_port,
'encryption' => $mailSetting->mail_encryption,
'username' => $mailSetting->mail_username,
'password' => Crypt::decryptString($mailSetting->mail_password),
])
->to($customer_email)
->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);
}
}`
bu şekilde yaptım ama sürümden kaynaklı herhalde hata alıyorum.
laravel sürümüm; "laravel/framework": "^ 10.0",
OfferMail.php dosyam;
`
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
]
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}
`
offertMail.blade.php
<!doctype html>
<html>
<body>
<h1>Teklif Detayları</h1>
<p>Teklif UUID: {{ $offer->uuid }}</p>
<!-- Diğer teklif bilgilerini buraya ekleyebilirsiniz -->
</body>
</html>