File: /home/inveservice/public_html/phpmailer/survey_phpmailer_smtp.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="Ansonika">
<title></title>
<!-- Favicons-->
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon">
<link rel="apple-touch-icon" type="image/x-icon" href="img/apple-touch-icon-57x57-precomposed.png">
<link rel="apple-touch-icon" type="image/x-icon" sizes="72x72" href="img/apple-touch-icon-72x72-precomposed.png">
<link rel="apple-touch-icon" type="image/x-icon" sizes="114x114" href="img/apple-touch-icon-114x114-precomposed.png">
<link rel="apple-touch-icon" type="image/x-icon" sizes="144x144" href="img/apple-touch-icon-144x144-precomposed.png">
<!-- GOOGLE WEB FONT -->
<link href="https://fonts.googleapis.com/css?family=Work+Sans:400,500,600" rel="stylesheet">
<!-- BASE CSS -->
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/style.css" rel="stylesheet">
<link href="../css/vendors.css" rel="stylesheet">
<!-- YOUR CUSTOM CSS -->
<link href="../css/custom.css" rel="stylesheet">
<script type="text/javascript">
function delayedRedirect(){
window.location = "../index.html"
}
</script>
</head>
<body onLoad="setTimeout('delayedRedirect()', 8000)" style="background-color:#fff;">
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
$mail = new PHPMailer(true);
try {
//Server settings
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtpserver'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients - main edits
$mail->setFrom('info@wilio.com', 'Message from Wilio'); // Email Address and Name FROM
$mail->addAddress('jhon@wilio.com', 'Jhon Doe'); // Email Address and Name TO - Name is optional
$mail->addReplyTo('noreply@wilio.com', 'Message from Wilio'); // Email Address and Name NOREPLY
$mail->isHTML(true);
$mail->Subject = 'Message from Wilio'; // Email Subject
//The email body message
$message = "<strong>User Info</strong><br />";
$message .= "First name: " . $_POST['firstname'] . "<br />";
$message .= "Last name: " . $_POST['lastname'] . "<br />";
$message .= "Email: " . $_POST['email'] . "<br />";
$message .= "Country: " . $_POST['country'] . "<br />";
$message .= "Age: " . $_POST['age'] . "<br />";
$message .= "Gender: " . $_POST['gender'] . "<br />";
$message .= "Terms and conditions accepted: " . $_POST['terms'] . "<br />";
$message .= "<br />How do rate your overall satisfaction about the service provided: " . $_POST['question_1'] . "<br />";
$message .= "<br />How did you hear about our company:<br />" ;
foreach($_POST['question_2'] as $value)
{
$message .= "- " . trim(stripslashes($value)) . "<br />";
};
$message .= "<br />Do you think to suggest our company to a friend or parent: " . $_POST['question_3'];
if( isset( $_POST['additional_message'] ) && $_POST['additional_message']) {
$message .= "<br />Additional Message: " . $_POST['additional_message'];
}
$mail->Body = "" . $message . "";
$mail->send();
// Confirmation/autoreplay email send to who fill the form
$mail->ClearAddresses();
$mail->isSMTP();
$mail->addAddress($_POST['email']); // Email address entered on form
$mail->isHTML(true);
$mail->Subject = 'Confirmation'; // Custom subject
$mail->Body = "" . $message . "";
$mail->Send();
echo '<div id="success">
<div class="icon icon--order-success svg">
<svg xmlns="http://www.w3.org/2000/svg" width="72px" height="72px">
<g fill="none" stroke="#8EC343" stroke-width="2">
<circle cx="36" cy="36" r="35" style="stroke-dasharray:240px, 240px; stroke-dashoffset: 480px;"></circle>
<path d="M17.417,37.778l9.93,9.909l25.444-25.393" style="stroke-dasharray:50px, 50px; stroke-dashoffset: 0px;"></path>
</g>
</svg>
</div>
<h4><span>Request successfully sent!</span>Thank you for your time</h4>
<small>You will be redirect back in 5 seconds.</small>
</div>';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
<!-- END SEND MAIL SCRIPT -->
</body>
</html>