This the php code for automatic mail sending.
<?php
$mailto = $_POST['mail_to'];
$mailSub = $_POST['mail_sub'];
$mailMsg = $_POST['mail_msg'];
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail ->IsSmtp();
$mail ->SMTPDebug = 4;
$mail ->SMTPAuth = true;
$mail ->SMTPSecure = 'ssl';
$mail ->Host = "smtp.gmail.com";
$mail ->Port = 587; // or 465
$mail ->IsHTML(true);
$mail ->Username = "[email protected]";
$mail ->Password = "************************";
$mail ->SetFrom("[email protected]");
$mail ->Subject = $mailSub;
$mail ->Body = $mailMsg;
$mail ->AddAddress($mailto);
if(!$mail->Send())
{
echo "Mail Not Sent";
}
else
{
echo "Mail Sent";
}
?>
after running the code i get this error as followed.
2018-03-08 01:33:32 Connection: opening to ssl://smtp.gmail.com:587, timeout=300, options=array () 2018-03-08 01:33:33 Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol [C:\xampp\htdocs\email\PHPMailer\class.smtp.php line 298] 2018-03-08 01:33:33 Connection failed. Error #2: stream_socket_client(): Failed to enable crypto [C:\xampp\htdocs\email\PHPMailer\class.smtp.php line 298] 2018-03-08 01:33:33 Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:587 (Unknown error) [C:\xampp\htdocs\email\PHPMailer\class.smtp.php line 298] 2018-03-08 01:33:33 SMTP ERROR: Failed to connect to server: (0) SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
$mail->SMTPSecure = 'tls';
ssl is dated and that advices is in the link you posted, so maybe read the troubleshooting guide before asking – user6763587