我正在努力使PHPMailer工作,但它一直给我这个错误:
致命错误:第8行/home/a4588543/public_html/contact/mailtest/process.php中找不到“PHPMailer”类。
和第8行是:
$mail = new PHPMailer();
以下是代码:
<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "mysmtp-server"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "me@mydomain.com"; // SMTP username
$mail->Password = "pass"; // SMTP password
$mail->From = "me@mydomain.com";
$mail->FromName = "Online Request";
$mail->AddAddress("receiver@mydomain.com"); // name is optional
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Contact Form";
$mail->Body = $message;
$mail->AltBody = $message;
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
答案 0 :(得分:2)
如果您已将所有PHPMailer的源文件包含在同一目录中,并且您使用的是最新版本...我建议使用
require_once('PHPMailerAutoload.php');
$mail = new PHPMailer();
Autoload文件是一个很好的资源,在设置时可以省去很多工作。