<?php
require(" c:\users\jafarnejad\vendor\PHPMailer\PHPMailer");
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer;
if(isset($_POST['send'])){
    // getting post values
    $fname=$_POST['fname'];
    $toemail=$_POST['toemail'];
    $subject=$_POST['subject'];
    $message=$_POST['message'];
    $mail->isSMTP();                            // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';             // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                     // Enable SMTP authentication
    $mail->Username = 'yourgmailid@gmail.com';          // SMTP username
    $mail->Password = 'Your_Gmail_Password'; // SMTP password
    $mail->SMTPSecure = 'tls';                  // Enable TLS encryption, `ssl` also accepted
    
    $mail->Port = 587;                          // TCP port to connect to
    $mail->setFrom('yourgmailid@gmail.com', 'Your_Name');
    $mail->addReplyTo('yourgmailid@gmail.com', 'Your_Name');
    $mail->addAddress($toemail);   // Add a recipient
    // $mail->addCC('cc@example.com'); // Set CC Email here
    // $mail->addBCC('bcc@example.com'); // Set BCC Email here
    
    $mail->isHTML(true);  // Set email format to HTML
    
    $bodyContent=$message;
    
    $mail->Subject =$subject;
    $bodyContent = 'Dear'.$fname;
    $bodyContent .='<p>'.$message.'</p>';
    $mail->Body = $bodyContent;
    
    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
}
?>