【发布时间】: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