2012-02-23 69 views
1

我有wamp server2,但我安裝了phpmailer5會導致任何問題? 我的php.ini 我用this sitesmtp的PHP郵件沒有響應

這裏是代碼:

<?php 
require_once('./PHPMailer_v5.1/class.phpmailer.php'); 
define('GUSER','[email protected]'); // GMail username 
define('GPWD','mypass'); // GMail password 
function smtpmailer($to, $from, $from_name, $subject, $body) { 
     global $error; 
     $mail = new PHPMailer(); // create a new object 
     $mail->IsSMTP(); // enable SMTP 
     $mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only 
     $mail->SMTPAuth = true; // authentication enabled 
     $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail 
     $mail->Host = 'smtp.gmail.com'; 
     $mail->Port = 25; 
     $mail->Username = GUSER; 
     $mail->Password = GPWD; 
     $mail->SetFrom($from, $from_name); 
     $mail->Subject = $subject; 
     $mail->Body = $body; 
     $mail->AddAddress($to); 
     if(!$mail->Send()) { 
       $error = 'Mail error: '.$mail->ErrorInfo; 
       return false; 
     } else { 
       $error = 'Message sent!'; 
       return true; 
     } 
} 
smtpmailer('[email protected]','[email protected]', 'phpmailer', 'test mail message', 'Hello World!'); 
if (smtpmailer('[email protected]','[email protected]', 'phpmailer', 'test mail message', 'Hello World!')) { 
    echo "sent"; 
} 
if (!empty($error)) echo $error; 
?> 

這裏是輸出:

SMTP Error: Could not connect to SMTP host. SMTP Error: Could not authenticate. Mail error: SMTP Error: Could not authenticate. 

然後我去爲php.ini並設定SMTPSERVER爲SMTP .google.com

SMTP = smtp.google.com 

再次沒有變化

+0

phpmailer不使用php.ini郵件設置。這些用於通常沒有安裝本地MTA並且必須使用外部服務的Windows盒子。 – 2012-02-23 19:00:27

+0

那有什麼問題?更改php.ini之前我也有問題 – Nickool 2012-02-23 19:03:27

+0

我有Windows系統 – Nickool 2012-02-23 19:10:19

回答

0

我剛剛測試了你的代碼(使用端口465),它的工作原理(我已將它發送到[email protected][email protected],以便你可以確認它)。您的問題代碼中仍然有25端口,請仔細檢查。另外請確保您提供正確的登錄名和密碼。

+0

謝謝但我相信我做的權利,端口25和465我都測試和功能smtpmailer我不知道不知道他爲什麼得到6個輸入,但寫了5個輸入這個功能我認爲這是一個錯誤,我嘗試了5個輸入沒有這個空輸入,但沒有結果 – Nickool 2012-02-24 07:05:48

+0

我再次編輯了代碼 – Nickool 2012-02-24 07:10:04