简体   繁体   中英

Error in sending SMTP mail

Try to send mail from window server using SMTP. and i get this error

Fatal error: Class 'SMTP' not found in...

and when i use PHPmailerAutoload.php only then it gives

Fatal error: Call to undefined method SMTP::setDebugLevel() in...

My code is

error_reporting(E_ALL);
ini_set('display_errors','1');
require_once('class.phpmailer.php');
include("class.smtp.php"); 

$mail = new PHPMailer(); 
$mail->IsSMTP();
$mail->SMTPDebug  = 1;
$mail->SMTPAuth   = true;
$mail->Host       = "mail.host.com.au";
$mail->Port       = 25;
$mail->Username   = "myusername";
$mail->Password   = "mypassword";
$mail->SetFrom('info@company.com.au', 'First Last');
$mail->AddReplyTo("info@company.com.au","First Last");
$mail->Subject    = "PHPMailer Test Subject";
$body             = "test";
$mail->MsgHTML($body);

$address = "myemail@gmail.com";
$mail->AddAddress($address, "John Doe");

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

Please provide any suggestion.

i had the same problem doing this.. and i resolved it.. Open your PHPMailer and in that class.phpmailer.php and in that add this line at the starting in the php block: require_once('class.smtp.php'); It'll surely work.. or you can download that two files from this link: https://github.com/abhishekpanjabi/e-Legal.git

Download phpmailer it has only two requird files and replace it with your phpmailer's files.. it'll work I've uploded image showing code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM