我有一個問題,使用smtp郵件類發送郵件時,當我使用我的本地系統smtp發送電子郵件代碼當時正在工作知府,但當我嘗試代碼在現場服務器時,我得到了每一個時間SMTP連接失敗錯誤smtp連接失敗的smtp郵件
我使用SMTP郵件類
require 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'tls';
$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]', 'Joe User');
$mail->addAddress('[email protected]');
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
$mail->WordWrap = 50;
$mail->isHTML(true);
$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';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';}
這是我的代碼,它在本地工作,但在直播服務器不能正常工作使用此代碼發送郵件
我做了所有設定我的php.ini文件喜歡smtp和用戶密碼 但仍然沒有工作,所以請給我正確的解決方案,或者在直播服務器運行的代碼
這是錯誤
2016-07-07 17:23:09 SMTP ERROR: Failed to connect to server: Network is unreachable (101) 2016-07-07 17:23:09 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
在.ini設置不會不管你的服務器主機地址。 phpmailer沒有使用它們。您需要檢查您的gmail服務器是否可以通過您正在測試的機器訪問。 –
將你的phpmailer errorinfo添加到你的問題。 – Progrock
請參閱:http://stackoverflow.com/questions/3675897/how-to-check-by-php-if-my-script-is-connecting-to-smtp-server – Progrock