pcs
pcs

Reputation: 1854

Error in php mailer in php

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

Upvotes: 0

Views: 612

Answers (1)

Abhinav
Abhinav

Reputation: 8168

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

Upvotes: 0

Related Questions