Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', '1');
- require_once 'phpmailer/PHPMailerAutoload.php';
- if (isset($_POST['inputName']) && isset($_POST['inputEmail'])&& isset($_POST['inputMessage'])) {
- //check if any of the inputs are empty
- if (empty($_POST['inputName']) || empty($_POST['inputEmail']) ||empty($_POST['inputMessage'])) {
- $data = array('success' => false, 'message' => 'Please fill out the form completely.');
- echo json_encode($data);
- exit;
- }
- //
- // Please make sure that you verify all the user input values before execute the below code
- //
- //create an instance of PHPMailer
- $mail = new PHPMailer();
- $mail->isSMTP();
- $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'user@example.com'; // SMTP username
- $mail->Password = 'secret'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = 587; // TCP port to connect to
- $mail->From = $_POST['inputEmail']; // this need to be your email account: noreply@mysite.com for example
- $mail->FromName = $_POST['inputName']; // this need to be your site title: My Site | Description
- // $mail->AddAddress('hola@iberomedia.com'); // recipient
- $mail->AddAddress( $_POST['inputEmail'] )
- $mail->Subject = 'Enquiry from Dexter';
- $mail->Body = "Name: " . $_POST['inputName'] . "\r\n\r\nMessage: " . stripslashes($_POST['inputMessage']);
- if (isset($_POST['ref'])) {
- $mail->Body .= "\r\n\r\nRef: " . $_POST['ref'];
- }
- if(!$mail->send()) {
- $data = array('success' => false, 'message' => 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo);
- echo json_encode($data);
- exit;
- }
- $data = array('success' => true, 'message' => 'Thanks! We have received your message.');
- echo json_encode($data);
- } else {
- $data = array('success' => false, 'message' => 'Please fill out the form completely.');
- echo json_encode($data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement