Advertisement
brilliantmojo

sendContact.php

Mar 15th, 2021 (edited)
1,332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.43 KB | None | 0 0
  1. <?php
  2.  
  3.     use PHPMailer\PHPMailer\PHPMailer;
  4.     use PHPMailer\PHPMailer\Exception;
  5.    
  6.     require('PHPMailer/src/PHPMailer.php');
  7.     require('PHPMailer/src/SMTP.php');
  8.     require('PHPMailer/src/Exception.php');
  9.  
  10.     $mail = new PHPMailer();
  11.  
  12.     // Server settings
  13.     $mail -> SMTPDebug = 0;
  14.     $mail -> IsSMTP();
  15.     $mail -> Mailer = "SMTP";
  16.     $mail -> Host = "smtp.office365.com";
  17.     $mail -> SMTPAuth = true;
  18.     $mail -> Username = "info@MyWebsite.com";
  19.     $mail -> Password = "Secret";
  20.     $mail -> SMTPSecure = "STARTTLS";
  21.     $mail -> Port = 587;  
  22.  
  23.    
  24.     // Recipient
  25.     $mail -> setFrom($_POST["ContactsEmail"], $_POST["ContactsName"]);
  26.     $mail -> AddReplyTo($_POST["ContactsEmail"], $_POST["ContactsName"]);
  27.     $mail -> addAddress("info@MyWebsite.com");
  28.     $mail -> Subject = "Contact Form - www.MyWebsite.com";
  29.     $mail -> WordWrap = 80;
  30.     $mail -> Body = "
  31.         <b>Name:</b> {$_POST['ContactsName']}<br />
  32.         <b>Email:</b> {$_POST['ContactsEmail']}<br />
  33.         <b>Phone:</b> {$_POST['ContactsPhone']}<br />
  34.         <b>Company:</b> {$_POST['ContactsCompany']}<br />
  35.         <b>Message:</b> {$_POST['ContactsMessage']}<br />
  36.         <b>Image:</b> {$ContactsFile}
  37.     ";
  38.  
  39.     if(!empty($_FILES["ContactsFile"]["name"])) {
  40.  
  41.         foreach($_FILES["ContactsFile"]["name"] as $k => $v) {
  42.  
  43.             $fileType = mime_content_type($_FILES["ContactsFile"]["name"]); // Get file (mime) extention/type
  44.                
  45.             $allowedTypes = array('image/jpeg', 'image/png', 'image/gif', 'image/tiff', 'application/pdf'); // Make an array of the allowed extentions (mime types)
  46.            
  47.             if(in_array($fileType, $allowedTypes)) {
  48.    
  49.                 $ContactsFile = 'CHECK FILE';
  50.    
  51.                 $mail -> AddAttachment($_FILES["ContactsFile"]["tmp_name"][$k], $_FILES["ContactsFile"]["name"][$k]);
  52.    
  53.             } else {
  54.                 $ContactError = 'Only .JPEG/.JPG, .PNG, .GIF, .TIFF/.TIF and .PDF files are accepted';
  55.                 $ContactError = '123';
  56.             }
  57.    
  58.         }
  59.  
  60.     } else {
  61.         $ContactsFile = 'NO IMAGE';
  62.     }
  63.  
  64.     $mail -> IsHTML(true);
  65.  
  66.     if($mail -> Send()) {
  67.  
  68.         echo "
  69.             <span class='ContactSuccess'>
  70.                 <span class='SendContainer'>
  71.                     <div class='mdi mdi-check-circle'></div>
  72.                     your message was sent
  73.                 </span>
  74.             </span>
  75.         ";
  76.  
  77.     } else {
  78.  
  79.         echo "
  80.             <span class='ContactError'>
  81.                 <span class='SendContainer'>
  82.                     <div class='mdi mdi-alert-circle'></div>
  83.                     there was a problem sending your message
  84.                     <div class='ContactErrorMessage'>
  85.                         " . $ContactError . "
  86.                     </div>
  87.                 </span>
  88.             </span>
  89.         ";
  90.         echo $mail -> ErrorInfo;
  91.     }
  92.  
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement