Advertisement
Guest User

Untitled

a guest
Jan 1st, 2018
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.55 KB | None | 0 0
  1. <?php
  2. require 'PHPMailer/PHPMailerAutoload.php';
  3. require 'PHPMailer/extras/Security.php';
  4.  
  5. define('SMTP_HOST', 'smtp.gmail.com'); // Hostname of the mail server
  6. define('SMTP_USERNAME', 'USERNAME@gmail.com'); // Username for SMTP authentication any valid email created in your domain
  7. define('SMTP_PASSWORD', 'YOUR_PASSWORD'); // Password for SMTP authentication
  8. define('SMTP_PORT', 587); // Port of the SMTP like to be 25, 80, 465 or 587
  9.  
  10. // To address who will receive this email
  11. $to = 'example@gmail.com';
  12.  
  13. $security = new Security();
  14.  
  15. // This IF condition is for improving security and Prevent Direct Access to the Mail Script.
  16. if (isset($_POST['name']) AND isset($_POST['email']) AND isset($_POST['subject']) AND isset($_POST['message']))
  17. {    
  18.     // Collect POST data from form
  19.     $name = $security->xss_clean($_POST['name']);
  20.     $email = $security->xss_clean($_POST['email']);
  21.     $subject = $security->xss_clean($_POST['subject']);
  22.     $services = ($_POST['services'] <> '') ? implode(',', $security->xss_clean($_POST['services'])) : '-';
  23.     $project_class = ($_POST['project_class'] <> '') ? $security->xss_clean($_POST['project_class']) : '-';
  24.     $message = $security->xss_clean($_POST['message']);
  25.    
  26.     // Prefedined Variables  
  27.     $set_from = 'BERG Notification Mailer';
  28.     $subject = 'BERG: Message from ' . $name . '!';
  29.  
  30.     // Collecting all content in HTML Table
  31.     $content = '<table width="100%">
  32.    <tr><td colspan="2"><strong>Contact Details:</strong></td></tr>
  33.    <tr><td valign="top">Name:</td><td>' . $name . '</td></tr>
  34.    <tr><td valign="top">Email:</td><td>' . $email . '</td></tr>
  35.    <tr><td valign="top">Subject:</td><td>' . $subject . '</td></tr>
  36.    <tr><td valign="top">Services:</td><td>' . $services . '</td></tr>
  37.    <tr><td valign="top">Project Class:</td><td>' . $project_class . '</td></tr>
  38.    <tr><td valign="top">Message:</td><td>' . $message . '</td></tr>
  39.    </table> ';
  40.    
  41.     $mail = new PHPMailer;
  42.     $mail->isSMTP();
  43.     $mail->SMTPDebug = 0;
  44.     $mail->Debugoutput = 'html';
  45.     $mail->Host = SMTP_HOST;
  46.     $mail->Port = SMTP_PORT;
  47.     $mail->SMTPSecure = 'tls';
  48.     $mail->SMTPAutoTLS = false;
  49.     $mail->SMTPAuth = TRUE;
  50.     $mail->Username = SMTP_USERNAME;
  51.     $mail->Password = SMTP_PASSWORD;
  52.    
  53.     $mail->setFrom(SMTP_USERNAME, $set_from);
  54.     $mail->addAddress($to);
  55.  
  56.     $mail->Subject = $subject;
  57.     $mail->msgHTML($content);
  58.    
  59.     // Send the message
  60.     $send = false;
  61.     if ($mail->send())
  62.     {
  63.         $send = true;
  64.     }
  65.  
  66.     echo json_encode($send);
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement