PHP Perl - mail/mime.php 无法打开流
PHP Perl - mail/mime.php failed to open stream
我需要一些帮助如何使用 Perl 发送电子邮件。
当我尝试 运行 此代码时:
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"] = 'sample@sampel.com';
$headers["To"] = "sample@sampel.com";
$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"] = "sample@sample.com";
$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
而且我不知道如何解决这个问题。请帮忙。
首先,这是 php,不是 Perl。如果你通过 perl 解释器提供它,你会得到与你得到的非常不同的各种错误。 (对不起,如果这听起来很刻薄......我打算提供信息。)
其次,错误信息非常有用。它说明了
允许的和不允许的
(include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear:/usr/lib/php/PEAR')
通常,这是因为路径或文件系统权限无效。
要排除文件系统权限是罪魁祸首,您可以检查是否允许每个人读取该文件(cd path/to/Mail; chmod a+r mime.php
in linux)。如果 "the user who runs the web server"(通常是非特权用户)无法读取文件(或者没有对 Mail 文件夹的执行权限,可以通过 cd path/to/Mail; cd ..; chmod a+x Mail
授予),则文件 Mail/mime.php无法导入(或要求)。根据环境的不同,文件系统权限可能会导致这些问题(不稳定的 Web 主机配置,在许多 linux 发行版上使用默认 umask
时自行滚动等)。这是第一个要看的地方。执行权限不仅在该文件夹上是必需的,而且在文件系统树的任何地方都是必需的。
您的 include_path 告诉您它在哪里寻找文件。这 '。'一开始说 "the current directory"。 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 所在的目录中。
基本上,如果没有关于文件权限和目录结构的信息,我们几乎无能为力。我希望这个常见问题的概述对您有所帮助。如果您可以更新您的问题以包含有关目录结构的信息并确认权限正确,其他人也许可以帮助您解决此问题。
确保您已经安装了所需的 PEAR 包。
Mail.php 是 "Mail" 的一部分,但 mime.php 是 "Mail_Mime" 的一部分。
pear install Mail Mail_Mime
我需要一些帮助如何使用 Perl 发送电子邮件。
当我尝试 运行 此代码时:
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"] = 'sample@sampel.com';
$headers["To"] = "sample@sampel.com";
$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"] = "sample@sample.com";
$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
而且我不知道如何解决这个问题。请帮忙。
首先,这是 php,不是 Perl。如果你通过 perl 解释器提供它,你会得到与你得到的非常不同的各种错误。 (对不起,如果这听起来很刻薄......我打算提供信息。)
其次,错误信息非常有用。它说明了
允许的和不允许的(include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear:/usr/lib/php/PEAR')
通常,这是因为路径或文件系统权限无效。
要排除文件系统权限是罪魁祸首,您可以检查是否允许每个人读取该文件(cd path/to/Mail; chmod a+r mime.php
in linux)。如果 "the user who runs the web server"(通常是非特权用户)无法读取文件(或者没有对 Mail 文件夹的执行权限,可以通过 cd path/to/Mail; cd ..; chmod a+x Mail
授予),则文件 Mail/mime.php无法导入(或要求)。根据环境的不同,文件系统权限可能会导致这些问题(不稳定的 Web 主机配置,在许多 linux 发行版上使用默认 umask
时自行滚动等)。这是第一个要看的地方。执行权限不仅在该文件夹上是必需的,而且在文件系统树的任何地方都是必需的。
您的 include_path 告诉您它在哪里寻找文件。这 '。'一开始说 "the current directory"。 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 所在的目录中。
基本上,如果没有关于文件权限和目录结构的信息,我们几乎无能为力。我希望这个常见问题的概述对您有所帮助。如果您可以更新您的问题以包含有关目录结构的信息并确认权限正确,其他人也许可以帮助您解决此问题。
确保您已经安装了所需的 PEAR 包。
Mail.php 是 "Mail" 的一部分,但 mime.php 是 "Mail_Mime" 的一部分。
pear install Mail Mail_Mime