SHARE
TWEET

Untitled

a guest Jun 24th, 2019 128 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // Import PHPMailer classes into the global namespace
  3. // These must be at the top of your script, not inside a function
  4. use PHPMailer\PHPMailer\PHPMailer;
  5. use PHPMailer\PHPMailer\Exception;
  6.  
  7. // Load Composer's autoloader
  8. require 'vendor/autoload.php';
  9.  
  10. // Instantiation and passing `true` enables exceptions
  11. $mail = new PHPMailer(true);
  12.  
  13. try {
  14.     //Server settings
  15.     $mail->SMTPDebug = 2;                                       // Enable verbose debug output
  16.     $mail->isSMTP();                                            // Set mailer to use SMTP
  17.     $mail->Host       = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
  18.     $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
  19.     $mail->Username   = 'user@example.com';                     // SMTP username
  20.     $mail->Password   = 'secret';                               // SMTP password
  21.     $mail->SMTPSecure = 'tls';                                  // Enable TLS encryption, `ssl` also accepted
  22.     $mail->Port       = 587;                                    // TCP port to connect to
  23.  
  24.     //Recipients
  25.     $mail->setFrom('from@example.com', 'Mailer');
  26.     $mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
  27.     $mail->addAddress('ellen@example.com');               // Name is optional
  28.     $mail->addReplyTo('info@example.com', 'Information');
  29.     $mail->addCC('cc@example.com');
  30.     $mail->addBCC('bcc@example.com');
  31.  
  32.     // Attachments
  33.     $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
  34.     $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
  35.  
  36.     // Content
  37.     $mail->isHTML(true);                                  // Set email format to HTML
  38.     $mail->Subject = 'Here is the subject';
  39.     $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
  40.     $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  41.  
  42.     $mail->send();
  43.     echo 'Message has been sent';
  44. } catch (Exception $e) {
  45.     echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top