【问题标题】:How to send data through email via phpmailer如何通过 phpmailer 通过电子邮件发送数据
【发布时间】:2015-08-19 10:18:33
【问题描述】:
<?php
      require 'mail/class.phpmailer.php';
      $mail = new PHPMailer();
      $mail->Host = 'mail.cancerbengal.com';
      $mail->Port = 465;
      $mail->SMTPSecure = 'ssl';
     /*** various $var declarations removed as irrelevant **/ 
     if(isset($_POST['submit']))
       {
       /**various irrelevant code removed**/
       }
       $mail->IsHTML(true); // if you are going to send HTML formatted emails
       $mail->SingleTo = true; 
      $mail->Subject = "Testing PHPMailer with localhost";
      $mail->Body = "You have received a new message. ".$messageContents;
      $file_to_attach = 'photo';
      $mail->AddAttachment( $file_to_attach , '$photo' );
      if(!$mail->Send())
                  {
                   echo "Message was not sent <br />PHPMailer Error: " .$mail->ErrorInfo;
                }
                else
                 {
        echo "<script>alert('Your Registration is Successfull')</script>";
                }

这是mail1.php在服务中,错误显示class.phmailer.php无法打开。如何解决?实际上,我想发送一封带有两个附件的邮件,但附件没有发送。任何帮助将不胜感激。错误是

错误输出:

警告:需要(mail/class.phpmailer.php):打开流失败:否 /home/cancerbengal/public_html/mail1.php 中的此类文件或目录 第 2 行

致命错误:require():需要打开失败 'mail/class.phpmailer.php' (include_path='.: /usr/lib/php : /usr/local/lib/php') 在 /home/cancerbengal/public_html/mail1.php 上 第 2 行

【问题讨论】:

  • 请提供实际错误信息和行号,同时在你的脚本中注明该行
  • class.phpmailer.php的路径是什么?
  • @Srrijita Daagupta 你确定 class.phpmailer.php 在邮件文件夹中吗?
  • 您的文件包含路径错误,phpmailer 位于何处?
  • 使用绝对路径来访问你的类,而不是相对路径,所以你可以从任何地方访问它:require $_SERVER["DOCUMENT_ROOT"] . '/mail/class.phpmailer.php';

标签: php


【解决方案1】:

您确实应该更新您的 PHPMailer 脚本以使用较新的 PHPMailer 并使用 autoloader 。我强烈推荐从 github 下载最新的 PHPMailer:

https://github.com/PHPMailer/PHPMailer

现在,您的问题是指定位置不存在该文件,

你在require 'mail/class.phpmailer.php';指定的位置

<sourcefile>
     |
     |
     \-----> mail folder / class.phpmailer.php 

这意味着:

  • 您没有将类文件上传到远程服务器。

  • 您的&lt;sourcefile&gt; 本身位于不同/不正确的位置

  • 如果您的 &lt;sourcefile&gt; 在其他脚本中是 included,则其中的包含相对于 它自己的位置,而不是它的“父”位置PHP 文件。

解决方案:

给包含路径一个绝对值,使用$_SERVER['DOCUMENT_ROOT'] 所以:

require "mail/class.phpmailer.php";

变成:

require $_SERVER['DOCUMENT_ROOT']."/mail/class.phpmailer.php";

无论您的&lt;sourcefile&gt; 位于何处,这都会起作用。

【讨论】:

    猜你喜欢
    • 2021-03-23
    • 1970-01-01
    • 2018-09-29
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    相关资源
    最近更新 更多