无法使用 Zend 库发送邮件
require_once 似乎不起作用。我正在尝试使用 Zend 库发送邮件,但有些东西不起作用。我正在使用我的网络托管服务器提供商,因此我必须将库放在子目录中(不安装任何框架)。
// $path= dirname(__FILE__)."/ZendLibrary:".get_include_path() ;
$path= "./ZendLibrary".PATH_SEPARATOR.get_include_path() ;
set_include_path($path);
//echo $path ;
echo "Spot 0" ;
require_once 'Zend/Mail.php';
echo "Spot 1" ;
我收到“Spot 0”消息,但我没有收到“Spot 1”消息。我只选择了两个 Zend 库:
ZendLibrary/Zend/Mail/* (directory)
ZendLibrary/Zend/Mime/* (directory)
ZendLibrary/Zend/Mail.php (script)
ZendLibrary/Zend/Mime.php (script)
ZendLibrary 是我的脚本所在目录中的一个文件夹。会发生什么?
UPDATE#1:
我的问题是,当我运行require_once时,代码停止工作。它不会回显“Spot 1”消息。我尝试过 set_include_path 的绝对路径,我尝试在没有内部 require_once 语句的情况下加载 .php 库脚本,但没有任何效果。由于我的测试是从互联网上的网络托管站点运行的,因此我无法访问日志!..或者我可以吗?
$path= realpath(dirname(__FILE__).'/ZendLibrary').PATH_SEPARATOR.get_include_path() ;
// $path= "./ZendLibrary".PATH_SEPARATOR.get_include_path() ;
set_include_path($path);
require_once does not seem to work. I am trying to use Zend libraries to send mail but something does not work. I am using my web hosting server provider so I have to put the libraries in a subdirectory (without installing any framework).
// $path= dirname(__FILE__)."/ZendLibrary:".get_include_path() ;
$path= "./ZendLibrary".PATH_SEPARATOR.get_include_path() ;
set_include_path($path);
//echo $path ;
echo "Spot 0" ;
require_once 'Zend/Mail.php';
echo "Spot 1" ;
I got the "Spot 0" message but I don't get the "Spot 1" message. I have selected only two Zend libraries:
ZendLibrary/Zend/Mail/* (directory)
ZendLibrary/Zend/Mime/* (directory)
ZendLibrary/Zend/Mail.php (script)
ZendLibrary/Zend/Mime.php (script)
ZendLibrary is a folder in the same directory where my script is. What could happening?
UPDATE#1:
My problem is that the code stops working right when I run require_once. It does not echo "Spot 1" message. I have tried absolute paths for set_include_path, I have tried to load a .php library script without internal require_once statements, but nothing makes it work. As my test is run from a web hosting site in the Internet I don't have access to logs!.. or do I?
$path= realpath(dirname(__FILE__).'/ZendLibrary').PATH_SEPARATOR.get_include_path() ;
// $path= "./ZendLibrary".PATH_SEPARATOR.get_include_path() ;
set_include_path($path);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Zend Mail 有一些依赖项。
硬依赖
Soft
最好是 添加所有 Zend 库到 PHP 中的包含路径,所有组件都会自动加载依赖项。
Zend Mail has some dependencies.
Hard dependencies
Soft
The best is to add all Zend library to the include path in PHP and all components will load the dependencies automatically.
您还没有满足所有依赖项...至少您还需要
Zend_Exception
(框架中的所有组件特定异常都扩展于此),但我很确定还有其他Mail
> 和Mime
取决于。为了让自己轻松起来,我还会使用Zend/Loader
并使用它进行自动加载。更新:
我看了一下,似乎您还需要
Zend/Validate
和Zend/Loader
这是其中之一所需要的Validate
组件中的类 - 尽管 Mail 仅使用Zend/Validate/Hostname
(这确实依赖于 Validate 的抽象类和接口以及Zend_Validate_Ip
>)所以你可能是可以不抓取Zend/Loader
,但您也可以将它用于通用自动加载。作为建议,您可以使用
[Swift Mailer
]1 代替...您将被打包避免依赖地狱,无论如何我更喜欢它。唯一的缺点是它用于发送邮件,而Zend_Mail
还可以让您读取本地或远程服务器上的邮件存储。You havent met all the dependencies... At the minimum you also need
Zend_Exception
(all component specific exceptions in the framework extend form this) but im pretty sure there are others thatMail
andMime
depend on. Just to make it easy on myself i would also grabZend/Loader
and use it for autoloading.Update:
I took a look and it seems as though you will also need
Zend/Validate
andZend/Loader
which is required by one of the classes inValidate
component - though Mail only usesZend/Validate/Hostname
(which does depend on the abstract classes and interfaces for Validate as well asZend_Validate_Ip
) so you might be able to get away with not grabbingZend/Loader
, but you might as well jsut make use of it for general purpose autoloading.As a suggestion you could use
[Swift Mailer
]1 instead... youll be bale to avoid dependency hell and i like it a lot better anyhow. Only down side is its for Sending mail, whileZend_Mail
will also let you read a mail store on a local or remote server.我之前使用 Zend_Mail 和 SMTP 独立运行,这里是我需要的文件。如果您也只想使用 sendmail,我还将其简化为您需要的内容。
如果你想使用Sendmail,那是最简单的。您的依赖项是:
对于这些文件,这里是一个使用示例:
如果您需要 SMTP,那么您有一个如 prodigitalson 所示,还有一些依赖项。除了上述之外,您至少还需要:
然后你可以这样做:
I used Zend_Mail with SMTP standalone before, here are the files I needed. I also reduced it down to what you need if you only want to use sendmail also.
If you want to use Sendmail, that is the easiest. Your dependencies are:
And with those files, here is an example use:
If you need SMTP, then you have a few more dependencies as prodigitalson showed. In addition to the above you need at least:
Then you can do something like this:
答案:
我的 ISP(网络托管)有一个设置来禁用 require_once。我能够在 VirtualBox 上设置 Unbuntu 虚拟机并设置 Web 服务器。我将测试网站的内容复制到 Unbuntu 中,发现 require_once 确实按预期工作!这可以解释为什么服务器端包含对我也不起作用。以下是一个有用的检查,它表明文件位于预期位置。
现在我必须找出它被禁用的原因,如何启用它,或者只是切换网络托管公司。 更新:我每年必须为提供商多支付 20 美元才能启用 PHP(在本例中是能够包含在内)。
这个网站可以告诉你更多相关信息。
Answer:
My ISP (web hosting too) has a setting to disable require_once. I was able to setup a Unbuntu virtual machine on VirtualBox and set up a web server. I copied the content of my test web site in my Unbuntu and find out that require_once does work as expected !!! That may explain why the server-side include did not work for me either. The following was a usefull check, that indicated me the file was in the expected place.
Now I have to find out why it is disabled, how to enable it, or just switch web hosting company. Update: I had to pay $20 dolars a year more for the provider to enable PHP (in this case to be able to include).
This site can tell you more about it.