Fonksiyonun Gerçekleşip Gerçekleşmediğini Kontrol Etme
6
●128
- 13-03-2022, 23:23:446.6.3 En son sürümü, eski sürümlerde sorun olduğunu görünce sorun yaşamamak adına yeni sürümü ayarladım mail gönderimi başarıyla çalışıyor fakat sweetalert mesajını çıkarmada sorun yaşıyorum.n3pix adlı üyeden alıntı: mesajı görüntüle
- 13-03-2022, 23:30:55Üyeliği durdurulduSorunun nereden kaynaklandığını tam olarak tespit edemiyorum fakat 3 tane varsayım sunabilirim;CodeTech adlı üyeden alıntı: mesajı görüntüle
1) mailgonder() fonksiyonu void bir fonksiyon, yani herhangi bir değer döndürmüyor. Bu sebeple if-else ifadesinde doğrudan else kısmıan giriyor. Bunu çözmek için fonksiyonun en altındaki ifadede "return $mail->send(); " şeklinde bir değişiklik yapıp deneyebilirsiniz.
2) Buna rağmen çalışmıyorsa durum $mail->send fonksiyonunun çalışma biçimiyle ilgilidir ki bana da bu daha yakın geliyor. https://github.com/PHPMailer/PHPMailer#a-simple-example bu linkte gösterilen örnekteki gibi bir düzenleme yaparsanız sizin için daha faydalı olur. try-catch bloğu dökümantasyonca da önerilen yöntemdir.
3) Yukarıdaki denemelere rağmen yine de çalışmıyorsa, başarılı çıktısının konumunun döküman içerisindeki yerinin; sweetalert kütüphanesinin eklenme sırasından geride olmasından kaynaklanabilir. Bunu da göz önünde bulundurun. - 13-03-2022, 23:36:36Üyeliği durdurulduhttps://github.com/PHPMailer/PHPMailer
<?php //Import PHPMailer classes into the global namespace //These must be at the top of your script, not inside a function use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; //Load Composer's autoloader require 'vendor/autoload.php'; //Create an instance; passing `true` enables exceptions $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output $mail->isSMTP(); //Send using SMTP $mail->Host = 'smtp.example.com'; //Set the SMTP server to send through $mail->SMTPAuth = true; //Enable SMTP authentication $mail->Username = 'user@example.com'; //SMTP username $mail->Password = 'secret'; //SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption $mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` //Recipients $mail->setFrom('from@example.com', 'Mailer'); $mail->addAddress('joe@example.net', 'Joe User'); //Add a recipient $mail->addAddress('ellen@example.com'); //Name is optional $mail->addReplyTo('info@example.com', 'Information'); $mail->addCC('cc@example.com'); $mail->addBCC('bcc@example.com'); //Attachments $mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name //Content $mail->isHTML(true); //Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body <b>in bold!</b>'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; $mail->send(); echo 'Message has been sent'; //Burası control exception varsa hata var demek } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; }(Bi bold yapacağım diye amma uğraştırdı ya.)