2014-03-13 60 views
0

我使用的XAMPP在Windows 7上,但我無法使用PHP無法(使用PHP腳本)

php.ini文件的一部分來發送郵件從XAMPP的Gmail發送郵件是在:

SMTP = smtp.gmail.com 
smtp_port = 25 
sendmail_from = hima***ivast***@gmail.com 
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t" 
mail.add_x_header = Off 

的sendmail.ini文件部分是爲下:

smtp_server=smtp.gmail.com 
smtp_port=25 
error_logfile=error.log 
debug_logfile=debug.log 
auth_username=hima***ivast***@gmail.com 
auth_password=************ 
force_sender=hima***ivast***@gmail.com 

請幫我找出錯誤。

回答

0

如果您在Gmail帳戶啓用了SSL,端口號是587,我相信其他的是465,按照幫助文檔:https://support.google.com/mail/answer/78775?hl=en

如果你試圖在端口465上配置您的SMTP服務器(與SSL)和 端口587(與TLS),但發送郵件仍然有問題,嘗試 配置您的SMTP使用端口25(與SSL)。

您應該也可能使用try/catch塊 - 如果sendmail失敗並出現錯誤,則可以使用print_r或var_dump查看異常消息包含的內容。

我應該承認我還沒有直接使用過sendmail;我發現的rmail庫很多更容易使用:

<?php 
    require_once(ROOT . DS . "libs" . DS . "Rmail" . DS . "Rmail.php"); 

    // Instantiate a new HTML Mime Mail object 
    $mail = new Rmail(); 

    $mail->setSMTPParams($host = 'smtp.gmail.com', $port = 587, $helo = null, $auth = true, $user = 'gmail address', $pass = 'password'); 

    // Set the From and Reply-To headers 
    $mail->setFrom("Proper Name <send from email address>"); 
    $mail->setReturnPath("reply email address"); 

    // Set the Subject 
    $mail->setSubject('Email subject/title'); 

    $html = 'you email message content'; 

    // Create the HTML e-mail 
    $mail->setHTML($html); 

    // Send the e-mail 
    $result = $mail->send(array('target email address')); 
?> 

我的地方追查庫中,如果你想用類似的代碼段的上方。

+0

所有三個端口都給出相同的結果。 – user3414154

+0

您是否驗證過您可以使用您使用的憑據登錄? –

+0

是的,我可以使用憑據登錄。我的代碼中有一些錯誤嗎? – user3414154