简体   繁体   English

如何设置梨邮件?

[英]How do I set up Pear mail?

I'm trying to set up php mail with pear. 我正在尝试用梨设置php邮件。 I've been trying and researching for the past 4 hours without success. 在过去的4个小时里,我一直在尝试和研究,但没有成功。

I'm using this code 我正在使用此代码

<?php
 require_once "Mail.php";

 $from = "Sandra Sender <sender@example.com>";
 $to = "Ramona Recipient <recipient@example.com>";
 $subject = "Hi!";
 $body = "Hi,\n\nHow are you?";

 $host = "ssl://mail.example.com";
 $port = "465";
 $username = "smtp_username";
 $password = "smtp_password";

 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'port' => $port,
     'auth' => true,
     'username' => $username,
     'password' => $password));

 $mail = $smtp->send($to, $headers, $body);

 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Message successfully sent!</p>");
  }
 ?>

And the 'require_once "Mail.php"' is giving this error: 并且'require_once“ Mail.php”'给出此错误:

Warning: require_once(Mail.php) [function.require-once]: failed to open stream: No such file or directory in /home/creatif2/public_html/mail.php on line 3 Fatal error: require_once() [function.require]: Failed opening required 'Mail.php' (include_path='.:php/') in /home/creatif2/public_html/mail.php on line 3 警告:require_once(Mail.php)[function.require-once]:无法打开流:在第3行的/home/creatif2/public_html/mail.php中没有此类文件或目录致命错误:require_once()[function.require ]:在第3行的/home/creatif2/public_html/mail.php中无法打开所需的'Mail.php'(include_path ='.: php /')

Pear and Pear Mail is installed 梨和梨邮件已安装

Auth_SASL 1.0.6 Update Reinstall Uninstall Show Docs Mail 1.2.0 Update Reinstall Uninstall Show Docs Net_SMTP 1.6.1 Update Reinstall Uninstall Show Docs Net_Socket 1.0.10 Update Reinstall Uninstall Show Docs Auth_SASL 1.0.6更新重新安装卸载Show Docs Mail 1.2.0更新重新安装卸载Show Docs Net_SMTP 1.6.1更新重新安装卸载Show Docs Net_Socket 1.0.10更新重新安装卸载Show Docs

And I'm quite baffled about it. 我对此感到困惑。 I think my problem is setting the include path but I'm not getting anywhere with it. 我认为我的问题是设置包含路径,但是我没有用。

The packages are located within the php folder - (eg home/my_user/php/Mail.php, I'm using Justhost). 安装放在php的文件夹中- (例如,家庭/ my_user / PHP / Mail.php,我使用Justhost的)。

The current configuration is .:/usr/lib/php:/usr/local/lib/php 当前配置是。:/ usr / lib / php:/ usr / local / lib / php

Can someone please explain to me how to reference the Mail.php file properly? 有人可以向我解释如何正确引用Mail.php文件吗? Been stuck here the whole morning and afternoon. 整个上午和下午都被困在这里。

Thanks 谢谢

I had the same problem when trying to send email. 尝试发送电子邮件时遇到了同样的问题。 You have to install the Pear Mail package with all the dependencies, I couldnt install until reinstall reinstalled the the PEAR Package Manager see http://pear.php.net/manual/en/installation.getting.php I'm sure this will help 您必须安装具有所有依赖项的Pear Mail软件包,直到重新安装重新安装PEAR软件包管理器后,我才能安装,请参见http://pear.php.net/manual/zh/installation.getting.php。救命

Your problem is that you are not using the correct path in the include. 您的问题是您未在包含项中使用正确的路径。 Assuming your include path starts in the document root, you should use: 假设您的包含路径始于文档根目录,则应使用:

require_once "/home/my_user/php/Mail.php";

Although it might take you some testing to find the correct path for the require 尽管可能需要您进行一些测试才能找到满足需求的正确路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM