I am trying to send mail using phpmailer but it is giving error
<?php
include("/mail/class.phpmailer.php");
// Basic Header Input
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->Username = 'username'; // your GMail user name
$mail->Password = 'password'; //"Password";
// ---------- adjust these lines ---------------------------------------
$mail->From= 'mg@gmail.com';
$mail->FromName="My site's mailer";
$mail->AddAddress("mg123@gmail.com");
$mail->Subject = "Your invoice";
$mail->IsHTML(false);
$mail->AddAttachment('test1.pdf', 'invoice.pdf'); // attach files/invoice-user-1234.pdf, and rename it to invoice.pdf
$mail->Body = "Please find your invoice attached.";
if(!$mail->Send())
{
echo "Error sending: " . $mail->ErrorInfo;;
}
else
{
echo "Letter is sent";
}
?>
it is showing error like Error sending:
"Error sending: The following From address failed: mg@gmail.com : Called Mail() without being connected"
i try with adding code $mail->SMTPDebug = 1; then it is showing error like below
SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0) The following From address failed: mg@gmail.com : Called Mail() without being connected