10/10/2018, 09:24
Hỏi về PHPMailer và SMTP
Mình mới down PHPMailer về và test thử chức năng gửi mail bằng smtp của nó, đây là vì dụ đi kèm của nó (mình có thêm 1 chút), nhưng gửi ko được và cũng không báo lỗi gì hết, account email(smtp,user,pass) của mình đã thử gửi thành công trên Outlook. Mong các bạn coi giúp mình nó sai chỗ nào.
Code:
<?php //error_reporting(E_ALL); error_reporting(E_STRICT); date_default_timezone_set('America/Toronto'); //date_default_timezone_set(date_default_timezone_get()); include_once('class.phpmailer.php'); include_once('phpmailer.lang-en.php'); //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(); $body = $mail->getFile('contents.html'); $body = eregi_replace("[]",',$body); $mail->Mailer ="smtp"; $mail->SMTPSecure="tls"; // telling the class to use SMTP $mail->Host = "mail.domain.com"; // SMTP server $mail->SMTPAuth = true; $mail->Username ="admin+domain.com"; $mail->Password ="UxCk8zKfGM"; $mail->From = "admin@domain.com"; $mail->FromName = "First Last"; $mail->Subject = "Test"; //$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $mail->AddAddress("***@gmail.com", "John Doe"); $mail->AddAttachment("images/phpmailer.gif"); // attachment if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?>
Bài liên quan
=> Bạn thêm port cho nó xem sao:?
$mail->Port = 587;
Code của mình sử dụng bạn có thể xem (Mình xài SMTP của Gmail)
Bạn thử chuyển:
error_reporting(E_STRICT);
sang thành:
error_reporting(E_ALL);
Để coi bị báo lỗi gì để biết đường khắc phục.
Khi mình sử dụng gmail thì nó báo lỗi:
Nếu không thì bạn vào www.inbox.com đăng ký một tài khoản, nó cho SMTP đó. Đặc biệt là nó cũng không bị dính Blacklist ở đâu hết nên gởi toàn vào Inbox và nhanh lắm