亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHPMailer 無法在實時服務器上發送電子郵件

PHPMailer 無法在實時服務器上發送電子郵件

PHP
慕虎7371278 2022-07-29 10:51:55
我相信以前有人問過這個問題,但我似乎無法找到解決問題的方法。我正在使用 PHPMailer 處理網站上的電子郵件。在本地主機上一切正常,但在實時服務器上不起作用。這是我的代碼:<?phprequire 'PHPMailerAutoload.php';$mail = new PHPMailer;$mail->IsSMTP();$mail->Host='smtp.gmail.com';$mail->Port=587;$mail->SMTPAuth=true;$mail->SMPTSecure='tls';$mail->SMTPDebug = 3;$mail->Username='*********';$mail->Password='*********';$mail->setFrom('*********', '********* Booking', 0);$mail->addAddress('*********');$name = "First Name :" . $_POST['firstname'] . "<br>";$email = "Email :" . $_POST['email'] . "<br>";$number = "Contact Number :" . $_POST['number'] . "<br>";$message = "message :" . $_POST['message'] . "<br>";$truck = "Truck Selected :" . $_POST['item'] . "<br>";$mail->isHTML(true);$mail->Subject='********* Booking';$mail->Body= "$name $email $number $message $truck";if(!$mail->send()) {  echo 'Message was not sent.';  echo 'Mailer error: ' . $mail->ErrorInfo;} else {  header('Location: /index.php');  echo 'Message was sent.';  exit;}使用上述代碼在實時服務器上發送電子郵件會導致以下結果:2020-01-22 07:51:48 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()2020-01-22 07:51:48 Connection failed. Error #2: stream_socket_client() [<a href='function.stream-socket-client'>function.stream-socket-client</a>]: unable to connect to smtp.gmail.com:587 (Connection refused) [/websites/cv/*********/phpmailer/class.smtp.php line 299]2020-01-22 07:51:48 SMTP ERROR: Failed to connect to server: Connection refused (111)SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/TroubleshootingMessage was not sent.Mailer error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting但是,如果我禁用$mail->IsSMTP();某些人建議的 ,則不會顯示錯誤,但不會發送/接收電子郵件。我嘗試過的事情:使用 ssl,端口 465在發送電子郵件時打開不太安全的應用程序聯系我的主機詢問是否有任何端口被阻止,他們說沒有確保 openssl 處于活動狀態確保登錄憑據正確做了所有這些事情后,它仍然說使用 SMTP 時連接被拒絕。有誰知道這可能是什么原因造成的?
查看完整描述

2 回答

?
GCT1015

TA貢獻1827條經驗 獲得超4個贊

這聽起來像是網絡/系統管理員問題,而不是 PHPMailer 問題。試試

telnet smtp.gmail.com 587  // host and port

在您的控制臺中,用于檢查連通性。如果一切正常,它應該寫一條消息,如“ESMTP MAIL 服務就緒”。否則,該服務器會阻止您的服務器。


查看完整回答
反對 回復 2022-07-29
?
慕的地10843

TA貢獻1785條經驗 獲得超8個贊

請在您的文件中添加類 smtp 或使用此代碼并相應地更改憑據它將起作用。


include_once('class.phpmailer.php');


 require_once('class.smtp.php');


$name = strip_tags($_POST['full_name']);

$email = strip_tags ($_POST['email']);

$msg = strip_tags ($_POST['description']);


$subject = "Contact Form from DigitDevs Website";


$mail = new PHPMailer();

$mail->IsSMTP();

$mail->CharSet = 'UTF-8';


$mail->Host       = "mail.example.com"; // SMTP server example

//$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)

$mail->SMTPAuth   = true;                  // enable SMTP authentication

$mail->Port       = 26;                    // set the SMTP port for the GMAIL server

$mail->Username   = "[email protected]"; // SMTP account username example

$mail->Password   = "password";        // SMTP account password example


$mail->From = $email;

$mail->FromName = $name;


$mail->AddAddress('[email protected]', 'Information'); 

$mail->AddReplyTo($email, 'Wale');


$mail->IsHTML(true);


$mail->Subject = $subject;


$mail->Body    =  $msg;

$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';


if(!$mail->Send()) {

echo 'Message could not be sent.';

echo 'Mailer Error: ' . $mail->ErrorInfo;

exit;

}

 echo 'Message has been sent';


查看完整回答
反對 回復 2022-07-29
  • 2 回答
  • 0 關注
  • 129 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號