Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $pesan = "";
- if (isset($_POST['submit'])) {
- require 'phpmailer/PHPMailerAutoload.php';
- function sendemail($to, $subject, $body, $attachment){
- $mail = new PHPMailer();
- $mail->isSMTP();
- $mail->Host = 'smtp.office365.com';
- $mail->SMTPAuth = true;
- $mail->Username = 'test@gmail.com';
- $mail->Password = '123456';
- $mail->SMTPSecure = 'auto';
- $mail->Port = 587;
- $mail->setFrom('test@gmail.com', 'admin');
- $mail->addAddress($to);
- $mail->addAttachment($attachment);
- $mail->Body = $body;
- $mail->isHTML(false);
- return $mail->send();
- }
- $to = $_POST['email'];
- $subjects = $_POST['subject'];
- $body = $_POST['body'];
- //$attachment = $_FILES['attachment'];
- $file = "attachment/" . basename($_FILES['attachment']['name']);
- if (move_uploaded_file($_FILES['attachment']['tmp_name'], $file)) {
- if (sendemail($to, $subjects, $body, $file))
- $msg = "email was sent";
- else
- $msg = "failed to send;
- } else
- $msg = "please try again";
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>form email</title>
- <link href="css/bootstrap.min.css" rel="stylesheet">
- <link href="css/style.css" rel="stylesheet">
- </head>
- <body>
- <div class="container-fluid">
- <div class="row">
- <div class="col-md-8">
- <form role="form" method="post" action="index.php" enctype="multipart/form-data">
- <div class="form-group">
- <label for="exampleInputEmail1">
- To email
- </label>
- <input type="email" name="email" class="form-control">
- </div>
- <div class="form-group">
- <label>
- Subject
- </label>
- <input type="text" name="subject" class="form-control">
- </div>
- <div class="form-group">
- <label for="exampleInputFile">
- Attachment
- </label>
- <input type="file" name="attachment" id="exampleInputFile">
- </div>
- <textarea name="body" rows="8" cols="122"></textarea>
- </div><br>
- <div class="col-md-4">
- <input type="submit" name="submit" class="btn btn-primary btn-lg active" value = "send email"><br><br>
- </div>
- </form><br><br>
- <?php echo $msg; ?>
- </div>
- </div>
- <script src="js/jquery.min.js"></script>
- <script src="js/bootstrap.min.js"></script>
- <script src="js/scripts.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement