Advertisement
AMONRA75

PHP - PHPMAILER

Mar 21st, 2018
1,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.61 KB | None | 0 0
  1.  
  2. sudo apt install composer
  3.  
  4. install phpmailer from composer
  5.  
  6. composer require phpmailer/phpmailer
  7.  
  8.  
  9.  
  10. use PHPMailer\PHPMailer\PHPMailer;
  11. use PHPMailer\PHPMailer\Exception;
  12.  
  13. require 'PHPMailer/src/Exception.php';
  14. require 'PHPMailer/src/PHPMailer.php';
  15. require 'PHPMailer/src/SMTP.php';
  16.  
  17.  
  18.  
  19.  
  20. /*
  21.     $mail = new PHPMailer(true);
  22.     $mail->SMTPDebug = 4;
  23.     $mail->isSMTP();
  24.     $mail->Host = 'smtp.googlemail.com';  //gmail SMTP server
  25.     $mail->SMTPAuth = true;
  26.     $mail->Username = 'pacal75.2@gmail.com';   //username
  27.     $mail->Password = 'Popolvuh2012';   //password
  28.     $mail->SMTPSecure = 'ssl';
  29.     $mail->Port = 465;                    //SMTP port
  30.  
  31.     $mail->setFrom('noreply@polotradez.net', 'Polotradez');
  32.     $mail->addAddress('pacal75@gmail.com', 'User Name');
  33.    
  34.     $mail->isHTML(true);
  35.    
  36.     $mail->Subject = 'New Execute!';
  37.    
  38.    
  39.    
  40.     $mail->Body = '<html><body>
  41.     <table style="border-collapse: collapse; width: 100%;" border="1">
  42.     <tbody>
  43.     <tr style="height: 21px;">
  44.     <td style="width: 100%; text-align: center; height: 21px;"><span style="color: #339966;"><strong>NEW ORDER EXECUTE!</strong></span></td>
  45.     </tr>
  46.     <tr style="height: 21px;">
  47.     <td style="width: 100%; text-align: center; height: 21px;"></td>
  48.     </tr>
  49.     <tr style="height: 21px;">
  50.     <td style="width: 100%; text-align: center; height: 21px;"><strong>PAIRS</strong></td>
  51.     </tr>
  52.     <tr style="height: 21px;">
  53.     <td style="width: 100%; text-align: center; height: 21px;"><span style="color: #ff0000;">xxx</span></td>
  54.     </tr>
  55.     <tr style="height: 21px;">
  56.     <td style="width: 100%; text-align: center; height: 21px;"><strong>TYPE</strong></td>
  57.     </tr>
  58.     <tr style="height: 21px;">
  59.     <td style="width: 100%; text-align: center; height: 21px;"><span style="color: #ff0000;">xxx</span></td>
  60.     </tr>
  61.     <tr style="height: 21px;">
  62.     <td style="width: 100%; text-align: center; height: 21px;"><strong>AMOUNT</strong></td>
  63.     </tr>
  64.     <tr style="height: 21px;">
  65.     <td style="width: 100%; text-align: center; height: 21px;"><span style="color: #ff0000;">xxx</span></td>
  66.     </tr>
  67.     <tr style="height: 21px;">
  68.     <td style="width: 100%; text-align: center; height: 21px;"><strong>DATE</strong></td>
  69.     </tr>
  70.     <tr style="height: 21px;">
  71.     <td style="width: 100%; text-align: center; height: 21px;"><span style="color: #ff0000;">xxx</span></td>
  72.     </tr>
  73.     <tr style="height: 21px;">
  74.     <td style="width: 100%; text-align: center; height: 21px;"><strong>RATE</strong></td>
  75.     </tr>
  76.     <tr style="height: 21px;">
  77.     <td style="width: 100%; text-align: center; height: 21px;"><span style="color: #ff0000;">xxx</span></td>
  78.     </tr>
  79.     <tr style="height: 21px;">
  80.     <td style="width: 100%; text-align: center; height: 21px;"><strong>TOTAL</strong></td>
  81.     </tr>
  82.     <tr style="height: 21px;">
  83.     <td style="width: 100%; text-align: center; height: 21px;"><span style="color: #ff0000;">xxx</span></td>
  84.     </tr>
  85.     <tr style="height: 21px;">
  86.     <td style="width: 100%; text-align: center; height: 21px;"><strong>TRADEID</strong></td>
  87.     </tr>
  88.     <tr style="height: 21px;">
  89.     <td style="width: 100%; text-align: center; height: 21px;"><span style="color: #ff0000;">XXX</span></td>
  90.     </tr>
  91.     </table></body></html>';
  92.    
  93.     if (!$mail->send()) {
  94.         echo 'Message could not be sent.';
  95.         echo 'Mailer Error: ' . $mail->ErrorInfo;
  96.     } else {
  97.         echo 'Message has been sent';
  98.  
  99.        
  100.     }
  101. */
  102.  
  103.  
  104.  
  105. $mail = new PHPMailer(true);                               // Passing `true` enables exceptions
  106. try {
  107.     //Server settings
  108.     $mail->isSMTP();                                       // Set mailer to use SMTP
  109.     $mail->SMTPDebug   = 3;                                // Enable verbose debug output
  110.     $mail->Debugoutput = "error_log";
  111.     $mail->Host        = 'smtp.gmail.com';                 // Specify main and backup SMTP servers
  112.     $mail->Port        = 587;                              // TCP port to connect to
  113.     $mail->SMTPAuth    = true;                             // Enable SMTP authentication
  114.     $mail->SMTPSecure  = 'tsl';                            // Enable TLS encryption, `ssl` also accepted
  115.     $mail->Username    = 'pacal75.2@gmail.com';        // SMTP username
  116.     $mail->Password    = 'Popolvuh2012';                         // SMTP password
  117.  
  118.  
  119.     $mail->SMTPOptions = array(
  120.         'ssl' => array(
  121.             'verify_peer' => false,
  122.             'verify_peer_name' => false,
  123.             'allow_self_signed' => true
  124.         )
  125.     );
  126.  
  127.  
  128.     //Recipients
  129.     $mail->setFrom('pacal75.2@gmail.com', 'Mailer');
  130.     $mail->addAddress('pacal75@gmail.com', 'Recipient User');      // Add a recipient
  131.     $mail->addReplyTo('sender@example.com', 'Information');
  132.  
  133. //  $mail->addAddress('to@example.com');                   // Name is optional
  134. //  $mail->addCC('cc@example.com');
  135. //  $mail->addBCC('bcc@example.com');
  136.  
  137.     //Attachments
  138. //  $mail->addAttachment('/var/tmp/file.tar.gz');          // Add attachments
  139. //  $mail->addAttachment('/tmp/image.jpg', 'new.jpg');     // Optional name
  140.  
  141.     //Content
  142.     $mail->isHTML(true);                                   // Set email format to HTML
  143.     $mail->CharSet     = "UTF-8";
  144.     $mail->Subject     = 'Here is the subject';
  145.     $mail->Body        = '<b>This is the HTML message body in bold!</b>';
  146.     $mail->AltBody     = 'This is the body in plain text for non-HTML mail clients';
  147.     $mail->WordWrap    = 80;
  148.  
  149.     $mail->send();
  150.     echo 'Message has been sent';
  151. }
  152. catch (Exception $e) {
  153.     echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement