myphp

Untitled

Jun 4th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2.  
  3. if (isset($_POST['form__submit'])) {
  4.    
  5.     // переменные, полученные из форм на сайте
  6.     $name = $_POST["name"];
  7.     $phone = $_POST["phone"];
  8.     $email = $_POST["email"];
  9.    
  10.     require_once 'PHPMailer/PHPMailerAutoload.php';
  11.  
  12.     $mail = new PHPMailer();
  13.     $mail->CharSet = 'utf-8';
  14.  
  15.     $email_body = "";
  16.     $email_body = $email_body . "<p>Имя:</p><h2>".$name."</h2><p>Телефон:</p><h2>".$phone."</h2><p>Email:</p><h2>".$email."</h2>";
  17.    
  18.     if (!empty($_FILES['file'])) {
  19.         $mail->addAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
  20.     }
  21.    
  22.     $mail->SetFrom('[email protected]', 'ПРО-Сцена');
  23.     $mail->AddAddress('[email protected]', 'Виталий');
  24.     $mail->Subject = 'Новая заявка с лендинга';
  25.     $mail->MsgHTML($email_body);
  26.  
  27.     if(!$mail->send()) {
  28.        echo 'Message could not be sent.';
  29.        echo 'Mailer Error: ' . $mail->ErrorInfo;
  30.        exit;
  31.     } else {
  32.         $redirect_url = '/thanks.html';
  33.         header("Location: http://".$_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . $redirect_url);
  34.         unset($_POST);
  35.         exit;
  36.     }
  37. }
  38.  
  39.  
  40. ?>
  41. <!DOCTYPE html>
  42. <html lang="ru">
  43. <head>
  44.     <title></title>
  45.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  46. </head>
  47. <body>
  48. <form action="" method="post" class="myform">
  49.  <input type="text" placeholder="Ваше имя:" class="input" name="name">
  50. <button type="submit" class="blue__btn" name="form__submit">Отправить</button>
  51. </form>
  52. </body>
Advertisement
Add Comment
Please, Sign In to add comment