0

I'm hosting my PHP documents on XAMPP (Apache, not sure why) and I don't want to use composer but still want to use PHPMailer. No matter where I place classes and index.php it always gives me an error require(): Failed opening required 'PHPMailerAutoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\PHPMailer-master\index.php on line 2

I've put my index.php in C:\xampp\htdocs\PHPMailer-master (directly downloaded from GitHub) and it still didn't work.

I've used code from this article: How to send an email using PHP?

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>
  • 2
    What version of PHPMailer are you using? Yes, it's possible to send an email without using Composer. [Read more.](https://github.com/PHPMailer/PHPMailer) – N'Bayramberdiyev Jul 27 '19 at 20:38

1 Answers1

1
require_once(APPPATH.'third_party/phpmailer/src/PHPMailer.php');
require_once(APPPATH.'third_party/phpmailer/src/SMTP.php');
$mail = new \PHPMailer(true);
//Server settings
$mail->isSMTP();
//$mail->SMTPDebug = 4;                                // Enable verbose debug output
$mail->CharSet = "utf-8";                                   // Set mailer to use SMTP
$mail->Host = 'localhost';  // Specify main and backup SMTP servers
$mail->SMTPAuth = false;                               // Enable SMTP authentication
$mail->Username = '';                 // SMTP username
$mail->Password = '';                           // SMTP password
$mail->SMTPSecure = 'ssl';       

$mail->Port = 25;//587; 
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
//Recipients
$mail->setFrom('noreply@mail.com', 'From name');
$mail->addAddress($mailData['to_email']);     // Add a recipient
//Content
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = "Subject";
$mail->Body    ="Html contetn";
$mail->send();
return  true;

Try to download phpmailer library from trusted source or you can copy the src folder from the phpmailer library downloaded via composer

Justin J
  • 808
  • 8
  • 14