I found the link to download PHPMailer but Im having trouble running the code. I have XAMPP installed and I'm confused on where to put the phpmailer installation. below is the sample code I found:

<?php
require 'PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myemail@gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, ssl also accepted
$mail->Port = 587; // TCP port to connect to

$mail->setFrom('myemail', 'CodexWorld');
$mail->addReplyTo('myemail@gmail.com', 'CodexWorld');
$mail->addAddress('myemail@gmail.com'); // Add a recipient
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

$mail->isHTML(true); // Set email format to HTML

$bodyContent = '<h1>How to Send Email using PHP in Localhost by CodexWorld</h1>';
$bodyContent .= '<p>This is the HTML email sent from localhost using PHP script by <b>CodexWorld</b></p>';

$mail->Subject = 'Email from Localhost by CodexWorld';
$mail->Body = $bodyContent;

if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>

I created a file called c:\xampp\htdocs\sendmail\sendmailexample.php with the above code

When I have this: require 'PHPMailer/PHPMailerAutoload.php';, i get the following error:

Warning: require(PHPMailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\sendemail\sendemailexample.php on line 2

Fatal error: require(): Failed opening required 'PHPMailer/PHPMailerAutoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\sendemail\sendemailexample.php on line 2

When I have this: require 'c:/xampp/htdocs/PHPMailer/PHPMailerAutoload.php' , I get this error:

Parse error: syntax error, unexpected '$mail' (T_VARIABLE) in C:\xampp\htdocs\sendemail\sendemailexample.php on line 5

Line 5 is: $mail = new PHPMailer;

When I downloaded the zip file I copied the contents of the zip folder to C:\xampp\htdocs\PHPMailer

Am I suppose to be doing something with my php.ini or sendmail.ini?

What is causing these errors?

    Write a Reply...