在本地測試郵件發送,郵件接收都沒有問題,但到阿里雲服務器上就出問題了,郵件服務就報錯了。通過仔細的排查,最後發現不是別的,而是阿里雲郵件發送的25端口被禁用,致使不能使用smtp協議.
須要到阿里雲去給這個25申請解禁,或者把端口換成465php
網上大量的信息說,將phpmailer中IsSMTP的smtp 改爲SMTP,實際上是有誤導性的服務器
/** * Sets Mailer to send message using SMTP. * @return void */ public function IsSMTP() { $this->Mailer = 'SMTP'; }
// Choose the mailer and send through it switch($this->Mailer) { case 'sendmail': return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody); case 'smtp': return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody); default: return $this->MailSend($this->MIMEHeader, $this->MIMEBody); }
上面改了之後,會走到php默認的mail方法,而不會使用smtp協議發送。這就突出了看源碼的重要性了測試