When I try to send email from my HTML form I get the following error message:
Warning: mail(): Failed to connect to mailserver at "smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Apache24\htdocs\WEB-SERVER\5.1.1 Epost-sändning utan bifogade filer\default.php on line 29
I have php 7.2 and apache24
And i have downloaded the files:
PHPMailerAutoload.php
class.phpmailer.php
class.smtp.php
class.pop3.php
and put them in the same catalog as my php file
I don't see what is wrong, i have also changed my SMTP och port in my php.ini
to the right ones. (465
and 'smtp.gmail.com
')
PHP code:
<?php
ini_set('SMTP','smtp.gmail.com');
ini_set('smtp_port',465);
require 'PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'filip.fellman@gmail.com';
$mail->Password = 'hejsan';
$mail->SMTPSecure = 'ssl';
if ($_POST["password"] == "hejsan") {
$from = $_POST["from"];
$to = $_POST["to"];
$cc = $_POST["cc"];
$bcc = $_POST["bcc"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$password = $_POST["password"] . "\n\n\n\nObservera! Detta meddelande är sänt från ett formulär på Internet och avsändaren kan vara felaktig!";
$headers = "From: " . $from . "\r\n" .
"Cc: " . $cc . "\r\n" .
"Bcc: " . $bcc;
mail($to, $subject, $message, $headers);
}else {
echo "Fel lösenord!";
}
?>
What's wrong?