0

I have been created, simple php code for sending email.

Here is the code:

index.html:

<form method="post" action="email.php">
  Email: <input name="email" id="email" type="text" /><br />

  Message:<br />
  <textarea name="message" id="message" rows="15" cols="40"></textarea><br />

  <input type="submit" value="Submit" />
</form>

error shows like this:

SMTP Error: Could not authenticate. Message could not be sent.

Mailer Error: SMTP Error: Could not authenticate.

May i know, what i am missing, how can i fix this error.

Thanks.,

Here is the code for php mailer

Community
  • 1
  • 1
pcs
  • 1,864
  • 4
  • 25
  • 49
  • possible duplicate of [Error handling with PHPMailer](http://stackoverflow.com/questions/2386544/error-handling-with-phpmailer) – Abdulla Nilam May 28 '15 at 11:56
  • according your link , i just confused, where i can add code and fix.. help? thanks – pcs May 28 '15 at 12:01

1 Answers1

0

Check php.ini file and verify that openssl.dll is uncommented .

EDIT: $mail->Host = "localhost"; // This must be the smtp server

Also you need to include the below configurations

$mail->SMTPSecure = 'tls';  // Enable TLS encryption, `ssl` also accepted
$mail->Port = your port number;  

NOTE:

Always initiate PHPMailer sending in the parameter true , because it helps you to catch the exceptions.

$mailer = new PHPMailer(true);

try {
 //set all the configurations
  $mailer->Send();//send  mail
  echo "Message Sent";
} catch (phpmailerException $e) {
  echo $e->errorMessage();
}

checkout the github link for usage phpmailer github link

Abhinav
  • 8,028
  • 12
  • 48
  • 89
  • checkout the edit... $mail->Host cannot be localhost, it must be a smtp server name – Abhinav May 28 '15 at 12:11
  • check the edited answer ....also checkout the github example of its usage, it might help you – Abhinav May 28 '15 at 12:12
  • Your code is wrong.....it will never work $mail->Host cannot be localhost you can use $mail->Host ="smtp.gmail.com" and provide any gmail address and password and try – Abhinav May 28 '15 at 12:17
  • you are getting that error because $mail is not being recognized as an object. try printing it and see what you get, try print_r($mail) after you initialize the phpmailer – Abhinav May 28 '15 at 12:25
  • Did you get the object when you tried to print it? I think the object is not being created may be because you did not include the phpmailer's class path properly – Abhinav May 28 '15 at 12:48