Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.65 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8.     <head>
  9.         <meta charset="UTF-8">
  10.         <title>Send email via Gmail SMTP server in PHP</title>
  11.         <link href="css/style.css" rel="stylesheet" type="text/css"/>
  12.     </head>
  13.     <body>
  14.         <div id="main">
  15.             <h1>Send Email via Gmail SMTP Server in PHP</h1>
  16.             <div id="login">
  17.                 <h2>Send Email</h2>
  18.                 <hr/>
  19.                 <form method="post">
  20.                     <input type="text" placeholder="Enter your Gmail ID" name="email"/>
  21.                     <input type="password" placeholder="Enter your Gmail Password" name="password"/>
  22.                     <input type="text" placeholder="To : Email Id " name="toid"/>  
  23.                     <input type="text" placeholder="Subject : " name="subject"/>
  24.                     <textarea rows="4" cols="50" placeholder="Enter Your Message..." name="message"></textarea>
  25.                     <input type="submit" value="Send" name="send"/>
  26.                 </form>    
  27.             </div>
  28.         </div>
  29.           <?php
  30.        
  31.               require 'phpmailer/PHPMailerAutoload.php';
  32.               if(isset($_POST['send']))
  33.                   {
  34.                     $email = $_POST['email'];                    
  35.                     $password = $_POST['password'];
  36.                     $to_id = $_POST['toid'];
  37.                     $message = $_POST['message'];
  38.                     $subject = $_POST['subject'];
  39.  
  40.                     $mail = new PHPMailer;
  41.  
  42.                     $mail->isSMTP();
  43.  
  44.                     $mail->Host = 'smtp.gmail.com';
  45.  
  46.                     $mail->Port = 587;
  47.  
  48.                     $mail->SMTPSecure = 'tls';
  49.  
  50.                     $mail->SMTPAuth = true;
  51.  
  52.                     $mail->Username = 'emailku';
  53.  
  54.                     $mail->Password = '.....';
  55.  
  56.                     $mail->setFrom('admin@l', 'Support');
  57.  
  58.                     //$mail->addReplyTo('replyto@example.com', 'First Last');
  59.  
  60.                     $mail->addAddress($to_id);
  61.  
  62.                     $mail->Subject = $subject;
  63.  
  64.                     $mail->msgHTML($message);
  65.  
  66.                     if (!$mail->send()) {
  67.                        $error = "Mailer Error: " . $mail->ErrorInfo;
  68.                         ?><script>alert('<?php echo $error ?>');</script><?php
  69.                     }
  70.                     else {
  71.                        echo '<script>alert("Message sent!");</script>';
  72.                     }
  73.                }
  74.         ?>
  75.     </body>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement