perl
  • php-5.5
  • 2015-04-01 56 views 0 likes 
    0

    我需要一些幫助如何使用Perl發送電子郵件。PHP Perl - 郵件/ mime.php未能打開流

    當我嘗試運行此代碼:

    require_once ("Mail.php"); 
    require_once ("Mail/mime.php"); 
    
    $text = "test"; 
    $html_message = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
    <title>....</title> 
    </head> 
    <body> 
        <p>...</p> 
    </body> 
    </html>'; 
    
    $headers["From"] = '[email protected]'; 
    $headers["To"] = "[email protected]"; 
    $headers["Subject"] = "Sample SMTP PERL"; 
    $headers["Content-Type"] = 'text/html; charset=UTF-8'; 
    $headers["Content-Transfer-Encoding"]= "8bit"; 
    
    $mime = new Mail_mime; 
    $mime->setTXTBody($text); 
    $mime->setHTMLBody($html_message); 
    $mimeparams=array(); 
    
    // It refused to change to UTF-8 even if the header was set to this, after adding the following lines it worked. 
    
    $mimeparams['text_encoding']="8bit"; 
    $mimeparams['text_charset']="UTF-8"; 
    $mimeparams['html_charset']="UTF-8"; 
    $mimeparams['head_charset']="UTF-8"; 
    
    $mimeparams["debug"] = "True"; 
    
    $body = $mime->get($mimeparams); 
    $headers = $mime->headers($headers); 
    $page_content = "Mail now."; 
    
    // SMTP server name, port, user/passwd 
    $smtpinfo["host"] = "xxx; 
    $smtpinfo["port"] = "465"; 
    $smtpinfo["auth"] = true; 
    $smtpinfo["username"] = "[email protected]"; 
    $smtpinfo["password"] = "xxx"; 
    $smtpinfo["debug"] = "True"; 
    
    
    // Create the mail object using the Mail::factory method 
    $mail=& Mail::factory("smtp", $smtpinfo); 
    
    $mail->send($to, $headers, $body)); 
    

    我得到這個錯誤信息:

    PHP Warning: require_once(Mail/mime.php): failed to open stream: No 
    such file or directory in /home3/xxx/public_html/xxx/zzz/ccc/vvv.php 
    on line 203 
    
    PHP Fatal error: require_once(): Failed opening required 
    'Mail/mime.php' 
    
    (include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear:/usr/lib/php/PEAR') 
    in /home3/xxx/public_html/xxx/zzz/ccc/vvv.php on line 203 
    

    而且我不知道如何解決。請幫忙。

    回答

    0

    首先,這是php,而不是Perl。如果你通過perl解釋器提供這些信息,你會得到與你所得到的很多不同的錯誤。 (對不起,如果這聽起來意味着...我打算它是信息。)

    其次,錯誤消息是非常有幫助的。它說什麼是允許的,並與

    (include_path中=」什麼是不:在/ usr/PHP/54的/ usr/lib64下:在/ usr/PHP/54的/ usr /共享/梨:/ usr/lib中/ php/PEAR')

    通常,這是由於路徑無效或文件系統權限。

    要排除文件系統權限是罪魁禍首,您可以檢查是否允許每個人讀取該文件(在Linux中爲cd path/to/Mail; chmod a+r mime.php)。如果「運行Web服務器的用戶」(通常是非特權用戶)無法讀取該文件(或者對郵件文件夾沒有執行權限(可以用cd path/to/Mail; cd ..; chmod a+x Mail授予該權限)),則Mail/mime.php文件不能被導入(或需要)。根據環境的不同,文件系統權限可能會導致這些問題(不穩定的Web主機配置,在許多Linux發行版上使用默認的umask等)。這是第一個看的地方。執行權限不僅在該文件夾上是必需的,而且在文件系統樹的任何位置都是必需的。

    你的include_path告訴你它在哪裏查找文件。 '。'在開頭說「當前目錄」。有可能Mail.php不會引發錯誤,因爲除了您認爲的那個之外,還有一些Mail.php可用。

    許多人建議始終使用絕對路徑而不是相對路徑(如require_once),以避免意外和意外行爲。

    這很大程度上取決於Mail.php和Mail/mime.php在相對於您的php腳本所在的目錄結構中的位置。你的PHP腳本的父文件夾是'。'。你需要確保Mail.php和Mail/mime.php的路徑是相對的。舉例來說,如果你有:

    /path/to/my/web/stuff/admin/this.php 
    /path/to/my/web/stuff/Mail.php 
    /path/to/my/web/stuff/Mail/mime.php 
    

    在this.php,你就不得不提到「../Mail.php」和「../Mail/mime.php」你require_once語句,因爲這些文件存在於this.php所在的目錄中。

    基本上,沒有關於文件權限和目錄結構的信息,我們很少提供。我希望這個常見問題的概述是有幫助的。如果您可以更新您的問題以包含有關目錄結構的信息並確認權限是正確的,則其他人可以幫助您解決此問題。

    相關問題