1

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

M Gaidhane
  • 531
  • 8
  • 29

1 Answers1

0

Change this,

$mail->From= 'mg@gmail.com';

You are mixing single quotes and double quotes

Vinod VT
  • 6,946
  • 11
  • 51
  • 75
  • Thanks for reply i have tried with this also but same error is there – M Gaidhane Sep 29 '14 at 06:52
  • 1
    @MGaidhane heck class.phpmailer.php is connected properly ? – Vinod VT Sep 29 '14 at 06:56
  • i checked it and it is working properly. i am getting error like..... "SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0)" – M Gaidhane Sep 29 '14 at 07:05