I'm trying to make one of those commonly known contact forms for a website, so that the user can directly send me an email from my website.
Here is the code I have so far
<html>
<body>
<?php
require("PHPMailer_5.2.0/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->Username = "[email protected]";
$mail->Password = "password";
//$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->From = "[email protected]";
$mail->FromName = "FROM NAME";
$mail->addAddress("[email protected]","Vik Kalkat");
$mail->Subject = "Testing PHPMailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";
if(!$mail->Send())
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
?>
</body>
</html>
The error I am getting is
SMTP Error: Could not connect to SMTP host. Message was not sent
PHPMailer Error: SMTP Error: Could not connect to SMTP host.
I'm guessing this may be because my "Username" and "Password" parameters might be wrong since I'm unsure what username and password is suppose to go here.
Is it the login information for the email account to which I want the emails to be sent to?
You should try using the TLS one
which is on port 587.
Change
to
another issue might be that your Mailer is 'smtp' instead of 'mail'