3

I'm trying to make PHPMailer work, but it keeps giving me this error:

Fatal error: Class 'PHPMailer' not found in /home/a4588543/public_html/contact/mailtest/process.php on line 8.

and line 8 is:

$mail = new PHPMailer();

Here's the code:

<?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";
?>
qwaz
  • 1,151
  • 3
  • 19
  • 45
  • 3
    does class.smtp.php exist in the same folder as your script resides (mailtest folder)? Did you spell PHPMailer correctly? It is case-sensitive – MonkeyZeus Sep 12 '13 at 12:27
  • 7
    Add `include_once("class.phpmailer.php");` before new instance and be sure you have `class.phpmailer.php` within `mailtest` dir. – Vahid Hallaji Sep 12 '13 at 12:30
  • This helped. Thank you very much – qwaz Sep 12 '13 at 13:55
  • Its good to know it MUST exist in the same folder, since in the instructions they never said It needed to. – Gucho Ca Jan 12 '14 at 01:17
  • It doesn't need to exist in the same folder if you use `require_once('./phpmailer/class.phpmailer.php');` (assuming 'phpmailer' is the exact name of the directory in which you have `class.phpmailer.php` and it is a subdirectory of 'mailtest'). – Agi Hammerthief Dec 18 '14 at 07:32

1 Answers1

2

If you have included all of PHPMailer's source files in the same directory, and you're using the latest version... I recommend using

require_once('PHPMailerAutoload.php');
$mail = new PHPMailer();

The Autoload file is a great resource which saves a lot of effort when setting it up.

Peter B
  • 372
  • 3
  • 14