i'm workin on my portfolio and, at the end of it, there is a form (name, email, message). This form needs to send an email to my personal gmail account but i'm having hard times trying to set global variables.
Form is working, this is the html code
<form action="" method="POST" id="contact-form">
<span class="contacts-text" id="first-contacts-text">To get in touch with me, please compile this form.</span>
<span class="contacts-text">I will reply as soon as possible. Thank you!</span>
<ul class="form-content">
<li class="form-input">
<label for="name" class="label">Full name</label>
<input class="input" id="name" type="text" name="name" required>
</li>
<li class="form-input">
<label for="email" class="label">E-mail</label>
<input class="input" id="mail" type="text" name="email" required>
</li>
<li class="form-input">
<label for="msg" class="label">Insert text</label>
<textarea class="input" id="comment" type="text" name="msg" cols="30" rows="10" style="resize: none;" required></textarea>
</li>
<li class="form-input" id="last-input">
<input class="input" id="form-button" type="submit" value="submit" name="submit" onclick="sendEmail()">
</li>
</ul>
</form>
My php code is
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->Host='smtp.gmail.com';
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Port=587;
$mail->SMTPAuth=true;
$mail->SMTPSecure='tls';
$mail->Username='myemail@gmail.com';
$mail->Password='mypassword';
$mail->setFrom('myotheremail@gmail.com'); //i know that i have to put here a variable for client email
$mail->addAddress('myemail@gmail.com');
$mail->isHTML(true);
$mail->Subject = 'Portfolio response';
$mail->Body = ''; // here probably another variable for the content
$mail->send();
echo '';
} catch (Exception $e){
echo 'Something went wrong!'. $mail->ErrorInfo;
}
this code works fine, i'm receiving emails, but i need help with those variables. Thanks in advance.