Excel'den veri çekerek PHPMailer ile toplu bir mail göndermeye çalışıyorum ancak şu şekilde bir hata almaktayım.
E-posta gönderimi başarısız: Invalid address: (to):bununla ilgili çözmeye çalıştım ancak pek başarılı olamadım.
Dipnot: Hatadan sonra mail server'ıma şu şekilde bir mail düşüyor.( https://prnt.sc/TdjFUHRJpljH )
Yardımcı olabilecek birileri var mıdır aramızda?
Kod;
<?php
// Gerekli kütüphaneleri yükle
require 'vendor/autoload.php';
// Kullanılacak sınıfları tanımla
use PhpOffice\PhpSpreadsheet\IOFactory;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
try {
// Excel dosyasını oku
$excel = IOFactory::load('test.xlsx');
$sayfa = $excel->getActiveSheet();
$musteriler = [];
// Excel dosyasındaki her satırı döngüye al
foreach ($sayfa->getRowIterator() as $satir) {
$hucre_iterator = $satir->getCellIterator();
$hucre_iterator->setIterateOnlyExistingCells(false);
$satir_veri = [];
// Her hücredeki veriyi oku
foreach ($hucre_iterator as $hucre) {
$satir_veri[] = $hucre->getValue();
}
$musteriler[] = $satir_veri;
}
// E-posta gönderimi için PHPMailer'ı ayarla
$posta = new PHPMailer(true);
$posta->isSMTP();
$posta->Host = 'mail hostum';
$posta->SMTPAuth = true;
$posta->Username = 'mail adresim';
$posta->Password = 'Mail Şifrem';
$posta->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // SSL için geçerlidir, TLS için değitirmeniz gerekir.
$posta->Port = 465;
$posta->CharSet = 'UTF-8';
$posta->setFrom('anil@anilkahraman.com.tr', 'Anıl Kahraman');
// Her müşteri için e-posta gönder
foreach ($musteriler as $musteri) {
$eposta = $musteri[0];
$isim = $musteri[1];
// E-posta alıcısını, konusunu ve içeriğini ayarla
$posta->addAddress($eposta);
$posta->isHTML(true);
$posta->Subject = 'Video Editörlüğü HK.';
$posta->Body = "<!DOCTYPE html>
<html lang='tr'>
<head>
<meta charset='UTF-8'>
</head>
<body>
<div class='content'>
<h3>Öncelikle Merhabalar $isim,</h3>
//Burada html olarak yazacağım body mesajım mevcut//
<p>Kendine çok dikkat et, <p/>
<p>İyi yayınlar.</p>
<p>Anıl Kahraman</p><br>
</div>
</body>
</html>";
// E-postayı gönder
$posta->send();
// Bir sonraki gönderim için alıcı adresini temizle
$posta->clearAddresses();
}
// İşlem başarılı mesajını göster
echo 'E-postalar başarıyla gönderildi';
} catch (Exception $e) {
// E-posta gönderim hatası durumunda hata mesajını göster
echo "E-posta gönderimi başarısız: {$posta->ErrorInfo}";
} catch (\PhpOffice\PhpSpreadsheet\Reader\Exception $e) {
// Excel dosyası okuma hatası durumunda hata mesajını göster
echo "Excel dosyası okuma hatası: {$e->getMessage()}";
}Yardımcı olabilecek birileri varsa çok mutlu olurum DoğrusuSevgilerle.