无法使用 Zend 库发送邮件

发布于 2024-12-29 13:06:09 字数 1116 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

日记撕了你也走了 2025-01-05 13:06:09

Zend Mail 有一些依赖项
硬依赖

  1. Zend_Exception
  2. Zend_Loader
  3. Zend_Mime
  4. Zend_Validate

Soft

  • Zend_Locale
  • Zend_Date
  • Zend_Filter
  • Zend_Registry

最好是 添加所有 Zend 库到 PHP 中的包含路径,所有组件都会自动加载依赖项。

Zend Mail has some dependencies.
Hard dependencies

  1. Zend_Exception
  2. Zend_Loader
  3. Zend_Mime
  4. Zend_Validate

Soft

  • Zend_Locale
  • Zend_Date
  • Zend_Filter
  • Zend_Registry

The best is to add all Zend library to the include path in PHP and all components will load the dependencies automatically.

热情消退 2025-01-05 13:06:09

您还没有满足所有依赖项...至少您还需要 Zend_Exception (框架中的所有组件特定异常都扩展于此),但我很确定还有其他 Mail > 和 Mime 取决于。为了让自己轻松起来,我还会使用 Zend/Loader 并使用它进行自动加载。

更新

我看了一下,似乎您还需要 Zend/ValidateZend/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 that Mail and Mime depend on. Just to make it easy on myself i would also grab Zend/Loader and use it for autoloading.

Update:

I took a look and it seems as though you will also need Zend/Validate and Zend/Loader which is required by one of the classes in Validate component - though Mail only uses Zend/Validate/Hostname (which does depend on the abstract classes and interfaces for Validate as well as Zend_Validate_Ip) so you might be able to get away with not grabbing Zend/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, while Zend_Mail will also let you read a mail store on a local or remote server.

情绪失控 2025-01-05 13:06:09

我之前使用 Zend_Mail 和 SMTP 独立运行,这里是我需要的文件。如果您也只想使用 sendmail,我还将其简化为您需要的内容。

如果你想使用Sendmail,那是最简单的。您的依赖项是:

  • Zend/Exception.php
  • Zend/Mail.php
  • Zend/Mime.php
  • Zend/Mail/Exception.php
  • Zend/Mail/Transport/Abstract.php
  • Zend/Mail/Transport/Exception.php Zend
  • /Mail/Transport/ Sendmail.php
  • Zend/Mime/Exception.php
  • Zend/Mime/Message.php
  • Zend/Mime/Part.php

对于这些文件,这里是一个使用示例:

<?php
// optionally
// set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/Zend');

require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Sendmail.php';

$transport = new Zend_Mail_Transport_Sendmail();

$mail = new Zend_Mail();
$mail->addTo('user@domain')
     ->setSubject('Mail Test')
     ->setBodyText("Hello,\nThis is a Zend Mail message...\n")
     ->setFrom('sender@domain');

try {
    $mail->send($transport);
    echo "Message sent!<br />\n";
} catch (Exception $ex) {
    echo "Failed to send mail! " . $ex->getMessage() . "<br />\n";
}

如果您需要 SMTP,那么您有一个如 prodigitalson 所示,还有一些依赖项。除了上述之外,您至少还需要:

  • Zend/Loader.php
  • Zend/Registry.php
  • Zend/Validate.php
  • Zend/Mail/Protocol/Abstract.php
  • Zend/Mail/Protocol/Smtp.php
  • Zend/Mail/Transport/Smtp .php
  • Zend/Validate/Abstract.php
  • Zend/Validate/Hostname.php
  • Zend/Validate/Interface.php
  • Zend/Validate/Ip.php
  • Zend/Validate/Hostname/*
  • Zend/Mail/Protocol/Smtp/Auth/*

然后你可以这样做:

<?php

require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';

$config    = array(//'ssl' => 'tls',
                   'port' => '25', //465',
                   'auth' => 'login',
                   'username' => 'user',
                   'password' => 'password');

$transport = new Zend_Mail_Transport_Smtp('smtp.example.com', $config);

$mail = new Zend_Mail();
$mail->addTo('user@domain')
     ->setSubject('Mail Test')
     ->setBodyText("Hello,\nThis is a Zend Mail message...\n")
     ->setFrom('sender@domain');

try {
    $mail->send($transport);
    echo "Message sent!<br />\n";
} catch (Exception $ex) {
    echo "Failed to send mail! " . $ex->getMessage() . "<br />\n";
}

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:

  • Zend/Exception.php
  • Zend/Mail.php
  • Zend/Mime.php
  • Zend/Mail/Exception.php
  • Zend/Mail/Transport/Abstract.php
  • Zend/Mail/Transport/Exception.php
  • Zend/Mail/Transport/Sendmail.php
  • Zend/Mime/Exception.php
  • Zend/Mime/Message.php
  • Zend/Mime/Part.php

And with those files, here is an example use:

<?php
// optionally
// set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/Zend');

require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Sendmail.php';

$transport = new Zend_Mail_Transport_Sendmail();

$mail = new Zend_Mail();
$mail->addTo('user@domain')
     ->setSubject('Mail Test')
     ->setBodyText("Hello,\nThis is a Zend Mail message...\n")
     ->setFrom('sender@domain');

try {
    $mail->send($transport);
    echo "Message sent!<br />\n";
} catch (Exception $ex) {
    echo "Failed to send mail! " . $ex->getMessage() . "<br />\n";
}

If you need SMTP, then you have a few more dependencies as prodigitalson showed. In addition to the above you need at least:

  • Zend/Loader.php
  • Zend/Registry.php
  • Zend/Validate.php
  • Zend/Mail/Protocol/Abstract.php
  • Zend/Mail/Protocol/Smtp.php
  • Zend/Mail/Transport/Smtp.php
  • Zend/Validate/Abstract.php
  • Zend/Validate/Hostname.php
  • Zend/Validate/Interface.php
  • Zend/Validate/Ip.php
  • Zend/Validate/Hostname/*
  • Zend/Mail/Protocol/Smtp/Auth/*

Then you can do something like this:

<?php

require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';

$config    = array(//'ssl' => 'tls',
                   'port' => '25', //465',
                   'auth' => 'login',
                   'username' => 'user',
                   'password' => 'password');

$transport = new Zend_Mail_Transport_Smtp('smtp.example.com', $config);

$mail = new Zend_Mail();
$mail->addTo('user@domain')
     ->setSubject('Mail Test')
     ->setBodyText("Hello,\nThis is a Zend Mail message...\n")
     ->setFrom('sender@domain');

try {
    $mail->send($transport);
    echo "Message sent!<br />\n";
} catch (Exception $ex) {
    echo "Failed to send mail! " . $ex->getMessage() . "<br />\n";
}
ˇ宁静的妩媚 2025-01-05 13:06:09

答案:

我的 ISP(网络托管)有一个设置来禁用 require_once。我能够在 VirtualBox 上设置 Unbuntu 虚拟机并设置 Web 服务器。我将测试网站的内容复制到 Unbuntu 中,发现 require_once 确实按预期工作!这可以解释为什么服务器端包含对我也不起作用。以下是一个有用的检查,它表明文件位于预期位置。

$file = 'ZendLibrary/Zend/Mail.php'; 

if ((!is_file($file)) or (!is_readable($file))) 
   die("File does not exists or is not readable."); 

现在我必须找出它被禁用的原因,如何启用它,或者只是切换网络托管公司。 更新:我每年必须为提供商多支付 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.

$file = 'ZendLibrary/Zend/Mail.php'; 

if ((!is_file($file)) or (!is_readable($file))) 
   die("File does not exists or is not readable."); 

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文