Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- require('PHPMailer/src/PHPMailer.php');
- require('PHPMailer/src/SMTP.php');
- require('PHPMailer/src/Exception.php');
- $mail = new PHPMailer();
- // Server settings
- $mail -> SMTPDebug = 0;
- $mail -> IsSMTP();
- $mail -> Mailer = "SMTP";
- $mail -> Host = "smtp.office365.com";
- $mail -> SMTPAuth = true;
- $mail -> Username = "info@MyWebsite.com";
- $mail -> Password = "Secret";
- $mail -> SMTPSecure = "STARTTLS";
- $mail -> Port = 587;
- // Recipient
- $mail -> setFrom($_POST["ContactsEmail"], $_POST["ContactsName"]);
- $mail -> AddReplyTo($_POST["ContactsEmail"], $_POST["ContactsName"]);
- $mail -> addAddress("info@MyWebsite.com");
- $mail -> Subject = "Contact Form - www.MyWebsite.com";
- $mail -> WordWrap = 80;
- $mail -> Body = "
- <b>Name:</b> {$_POST['ContactsName']}<br />
- <b>Email:</b> {$_POST['ContactsEmail']}<br />
- <b>Phone:</b> {$_POST['ContactsPhone']}<br />
- <b>Company:</b> {$_POST['ContactsCompany']}<br />
- <b>Message:</b> {$_POST['ContactsMessage']}<br />
- <b>Image:</b> {$ContactsFile}
- ";
- if(!empty($_FILES["ContactsFile"]["name"])) {
- foreach($_FILES["ContactsFile"]["name"] as $k => $v) {
- $fileType = mime_content_type($_FILES["ContactsFile"]["name"]); // Get file (mime) extention/type
- $allowedTypes = array('image/jpeg', 'image/png', 'image/gif', 'image/tiff', 'application/pdf'); // Make an array of the allowed extentions (mime types)
- if(in_array($fileType, $allowedTypes)) {
- $ContactsFile = 'CHECK FILE';
- $mail -> AddAttachment($_FILES["ContactsFile"]["tmp_name"][$k], $_FILES["ContactsFile"]["name"][$k]);
- } else {
- $ContactError = 'Only .JPEG/.JPG, .PNG, .GIF, .TIFF/.TIF and .PDF files are accepted';
- $ContactError = '123';
- }
- }
- } else {
- $ContactsFile = 'NO IMAGE';
- }
- $mail -> IsHTML(true);
- if($mail -> Send()) {
- echo "
- <span class='ContactSuccess'>
- <span class='SendContainer'>
- <div class='mdi mdi-check-circle'></div>
- your message was sent
- </span>
- </span>
- ";
- } else {
- echo "
- <span class='ContactError'>
- <span class='SendContainer'>
- <div class='mdi mdi-alert-circle'></div>
- there was a problem sending your message
- <div class='ContactErrorMessage'>
- " . $ContactError . "
- </div>
- </span>
- </span>
- ";
- echo $mail -> ErrorInfo;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement