0

Im trying to make a contact form, I searched alot on the web but didn't found any solution that works.

This is contact-form HTML and PHP:

<?php
if(isset($_POST['submit']))
{

  $message=
      'Name:    '.$_POST['name'].'<br />
  Subject:  '.$_POST['message'].'<br />
  Email:    '.$_POST['email'].'
  ';

  require 'class.phpmailer.php';
  require 'PHPMailerAutoload.php';

  // Instantiate Class
  $mail = new PHPMailer();
  // Set up SMTP
  $mail->IsSMTP();                // Sets up a SMTP connection
  $mail->SMTPAuth = true;         // Connection with the SMTP does require     authorization
  $mail->SMTPSecure = "tls";      // Connect using a TLS connection
  $mail->Host = "smtp.gmail.com";  //Gmail SMTP server address
  $mail->Port = 587;  //Gmail SMTP port

  // Authentication
  $mail->Username   = '**********@gmail.com'; // Your full Gmail address
  $mail->Password   = '**********'; // Your Gmail password

  $mail->SMTPDebug = 1;
  // Compose
  $mail->SetFrom($_POST['email'], $_POST['name']);
  $mail->AddReplyTo($_POST['email'], $_POST['name']);
  $mail->Subject = "New Contact Form Enquiry";      // Subject (which isn't required)
  $mail->MsgHTML($message);

  // Send To
  $mail->AddAddress("*********@gmail.com", "Recipient Name"); // Where to send it - Recipient
  $result = $mail->Send();      // Send!
  $message = $result ? 'Successfully Sent!' : 'Sending Failed!';
  unset($mail);
}
?>
<html>
<head>
<title>Contact Form</title>
</head>
<body>

  <div style="margin: 100px auto 0;width: 300px;">
    <h3>Contact Form</h3>
    <form name="form1" id="form1" action="" method="post">
      <fieldset>
        <input type="text" name="name" placeholder="Full Name" />
        <br />
        <input type="text" name="message" placeholder="Message" />
        <br />
        <input type="text" name="email" placeholder="Email" />
        <br />
        <input type="submit" name="submit" value="Send" />
      </fieldset>
    </form>
    <p><?php if(!empty($message)) echo $message; ?></p>
  </div>

</body>
</html>

I get this Error. I have the latest version of PHPMailer, Username and Password are correct.

Can someone please help?

Mat
  • 51
  • 1
  • 7
  • If u r using $mail->SMTPAuth = true; than chk yur user email and password are correct or not? – devpro Jan 16 '16 at 18:04
  • Or create a new email user and use it for testing – devpro Jan 16 '16 at 18:05
  • $mail->IsMail(); That way you don't need to use smtp and gmail. Works perfectly! – Chris G Jan 16 '16 at 18:21
  • @devpro Thanks.. just created a new account and it was fixed. Don't know why it didn't work. – Mat Jan 16 '16 at 19:45
  • @ChrisG I tried with the IsMail() but had error 'Could not instantiate mail function' – Mat Jan 16 '16 at 19:46
  • Hahahah... congrats well u can also reset the pswrd – devpro Jan 16 '16 at 19:46
  • Well plz share the solution with others it will help to others .. – devpro Jan 16 '16 at 20:18
  • Search before posting - this has been answered hundreds of times before, and this exact problem is covered in the troubleshooting guide that the error message links to. Really, just read what the message says, we're not here to do your thinking for you! – Synchro Jan 17 '16 at 13:40
  • 1
    Possible duplicate of [PHPMailer - SMTP ERROR: Password command failed when send mail from my server](http://stackoverflow.com/questions/21937586/phpmailer-smtp-error-password-command-failed-when-send-mail-from-my-server) – Synchro Jan 17 '16 at 13:41

0 Answers0