Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用PEAR邮件包发送邮件时出错_Php_Email_Phpmailer_Pear_Require Once - Fatal编程技术网

Php 使用PEAR邮件包发送邮件时出错

Php 使用PEAR邮件包发送邮件时出错,php,email,phpmailer,pear,require-once,Php,Email,Phpmailer,Pear,Require Once,我试图通过PHP Pear邮件包发送邮件,这里有两种情况,第一种情况下邮件正确发送,没有任何错误,但第二种情况下我收到错误消息 情景1: 文件名:testmail.php <?php require_once "Mail.php"; $from = "erp@askspidy.com"; $to = "support@askspidy.com"; $subject = "Landing Page Enquiry From -"; $body = "Hello just test

我试图通过PHP Pear邮件包发送邮件,这里有两种情况,第一种情况下邮件正确发送,没有任何错误,但第二种情况下我收到错误消息

情景1:

文件名:testmail.php

<?php
 require_once "Mail.php";

 $from = "erp@askspidy.com";
 $to = "support@askspidy.com";
 $subject = "Landing Page Enquiry From -";
 $body = "Hello just testing";

 $host = "ssl://mail.askspidy.com";
 $port = "465";
 $username = "support@askspidy.com";
 $password = "askspidy@1234";

 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject,
   'MIME-Version' => 1,
    'Content-type' => 'text/html;charset=iso-8859-1'
   );

 $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>");
  }
 ?>
<?php


    function send_mail($subject,$body)
    {
         require_once "Mail.php";

         $from = "erp@askspidy.com";
         $to = "support@askspidy.com";

         $host = "ssl://mail.askspidy.com";
         $port = "465";
         $username = "support@askspidy.com";
         $password = "askspidy@1234";

         $headers = array ('From' => $from,
           'To' => $to,
           'Subject' => $subject,
           'MIME-Version' => 1,
            'Content-type' => 'text/html;charset=iso-8859-1'
           );

         $smtp = Mail::factory('smtp',
           array ('host' => $host,
             'port' => $port,
             'auth' => true,
             'username' => $username,
             'password' => $password));


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

    }

?>
<?php

require_once("../sendmail.php");

$subject="Landing page enquiry";
$email_body="Hello Just Testing! ";

send_mail($subject,$email_body);

?>
 require_once "Net/SMTP.php";
错误:

Warning: include_once(Net/SMTP.php): failed to open stream: No such file or directory in /usr/local/lib/php/Mail/smtp.php on line 348

Warning: include_once(): Failed opening 'Net/SMTP.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /usr/local/lib/php/Mail/smtp.php on line 348

Fatal error: Class 'Net_SMTP' not found in /usr/local/lib/php/Mail/smtp.php on line 349
在场景1中一切正常,那么为什么在场景2中我会出现这个错误,我猜路径有问题,但我不确定路径应该是什么,应该包括在哪里

文件夹结构:

Warning: include_once(Net/SMTP.php): failed to open stream: No such file or directory in /usr/local/lib/php/Mail/smtp.php on line 348

Warning: include_once(): Failed opening 'Net/SMTP.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /usr/local/lib/php/Mail/smtp.php on line 348

Fatal error: Class 'Net_SMTP' not found in /usr/local/lib/php/Mail/smtp.php on line 349

在文件Mail/smtp.php中包含代码

<?php
 require_once "Mail.php";

 $from = "erp@askspidy.com";
 $to = "support@askspidy.com";
 $subject = "Landing Page Enquiry From -";
 $body = "Hello just testing";

 $host = "ssl://mail.askspidy.com";
 $port = "465";
 $username = "support@askspidy.com";
 $password = "askspidy@1234";

 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject,
   'MIME-Version' => 1,
    'Content-type' => 'text/html;charset=iso-8859-1'
   );

 $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>");
  }
 ?>
<?php


    function send_mail($subject,$body)
    {
         require_once "Mail.php";

         $from = "erp@askspidy.com";
         $to = "support@askspidy.com";

         $host = "ssl://mail.askspidy.com";
         $port = "465";
         $username = "support@askspidy.com";
         $password = "askspidy@1234";

         $headers = array ('From' => $from,
           'To' => $to,
           'Subject' => $subject,
           'MIME-Version' => 1,
            'Content-type' => 'text/html;charset=iso-8859-1'
           );

         $smtp = Mail::factory('smtp',
           array ('host' => $host,
             'port' => $port,
             'auth' => true,
             'username' => $username,
             'password' => $password));


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

    }

?>
<?php

require_once("../sendmail.php");

$subject="Landing page enquiry";
$email_body="Hello Just Testing! ";

send_mail($subject,$email_body);

?>
 require_once "Net/SMTP.php";

注意:我已经在Cpanel帐户中手动安装了PEAR包,并且没有在php.ini文件中进行任何设置

您可以使用
\uuuuu DIR\uuu
作为当前文件的目录路径

require_once __DIR__ . "/Net/SMTP.php";
将dirname(文件)添加到代码中任何地方的路径名中,它都能正常工作

require_once dirname(__FILE__)."/Net/SMTP.php";

你把你所有的要求都改变一次了吗。当您更改为此时,错误信息是什么?我在“require_once”home/askspidy/public_html/Mail/Net/SMTP.php”中使用了此路径,我收到了相同的错误消息,对于我的场景1,我也收到了类似致命错误的错误消息:require_once():在第358行/home/saniserv/public_html/SMTP.php中的/home/askspidy/public_html/Mail/Net/SMTP.php(include_path='):/opt php55/lib/php/php')打开所需的“home/askspidy/public_html/Mail/SMTP.php”失败,为什么不使用我的代码。在这里,您不能将
\uuuu DIR\uuu
值更改为您的路径。您需要编写
require\u once“\uuuuu DIR\uuuu/Net/SMTP.php”
在您的代码中,
\uuuuuu DIR\uuuuu
是一个php变量,它表示当前文件的路径。即使我添加DIR,也会出现相同的错误,致命错误:require_once():打开required'\uuuu DIR\uuuuu/Mail.php'失败(include_path=':/usr/lib/php:/usr/local/lib/php')
\uuuu DIR\uuuu
常量将不会在双引号字符串内插入。您需要使用
来连接它。