perl
  • php-5.5
  • 2015-04-01 69 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所在的目录中。

    基本上,没有关于文件权限和目录结构的信息,我们很少提供。我希望这个常见问题的概述是有帮助的。如果您可以更新您的问题以包含有关目录结构的信息并确认权限是正确的,则其他人可以帮助您解决此问题。

    相关问题