I have been stuck here for almost a week. I actually followed the steps in the tutorials, but had no luck. I downloaded this phpmailer and got version 5.4.2. the code below is an example of this downloaded phpmailer but it does not work for me. I have already configure the sendmail and php.ini. I have also enable some extensions such as php openssl and phpsocket php smtp and the apache module. I hope someone will help me with this problem,I hope. Here is my code below:

<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>

<?php

error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

require_once('../class.phpmailer.php');
class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = "dasdf";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                       // 1 = errors and messages
                                       // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "[email protected]";  // GMAIL username
$mail->Password   = "ggg";            // GMAIL password

$mail->SetFrom('[email protected]', 'jj');

$mail->AddReplyTo("[email protected]","jj");

$mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "[email protected]";
$mail->AddAddress($address, "Dave");

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

?>

</body>
</html>
1

There are 1 answers

0
Kelvin On

That version of PHPMailer is very out of date (last updated February 2013); it has been superseded by https://github.com/PHPMailer/PHPMailer

Before anything else, you should upgrade to the latest version; There's a good chance you're trying to work around a bug that's already been fixed.

You'll find the usage is almost identical; check the example on the GitHub page for the obvious differences in the current version.

You should also enable SMTP debugging by adding

$mail->SMTPDebug = 3;