簡體   English   中英

無法使用Xampp從gmail發送郵件(使用php腳本)

[英]Unable to send mail from gmail with xampp (using php script)

我在Windows 7上使用XAMPP,但無法使用php發送郵件

php.ini文件的部分如下所示:

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

請幫助我找到錯誤。

如果您在Gmail帳戶上啟用了SSL,則端口號是587。根據幫助文檔,我相信另一個是465。https: //support.google.com/mail/answer/78775?hl = zh_CN

如果您嘗試在端口465(帶有SSL)和端口587(帶有TLS)上配置SMTP服務器,但是仍然無法發送郵件,請嘗試將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' ) );
?>

如果您希望使用上面的代碼段,可以在某個地方找到該庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM