Advertisement
Guest User

Untitled

a guest
May 9th, 2018
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use PHPMailer\PHPMailer\PHPMailer;
  6. use PHPMailer\PHPMailer\Exception;
  7.  
  8. use Illuminate\Http\Request;
  9.  
  10. use App\Http\Requests;
  11.  
  12.  
  13. class EmailController extends Controller
  14. {
  15. public function index()
  16. {
  17.  
  18.  
  19. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  20. try {
  21. //Server settings
  22. $mail->SMTPDebug = 4; // Enable verbose debug output
  23. $mail->isSMTP(); // Set mailer to use SMTP
  24. $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
  25. $mail->SMTPAuth = true; // Enable SMTP authentication
  26. $mail->Username = 'emailsaya@gmail.com'; // SMTP username
  27. $mail->Password = ''; // SMTP password
  28. $mail->SMTPSecure = 'tsl'; // Enable TLS encryption, `ssl` also accepted
  29. $mail->Port = 465; // TCP port to connect to
  30.  
  31. //Recipients
  32. $mail->setFrom('ddd@yourdomain.com', 'Mailer');
  33. $mail->addAddress('tujuankirim@gmail.com', 'Joe User'); // Add a recipient
  34. // $mail->addAddress('ellen@example.com'); // Name is optional
  35. // $mail->addReplyTo('info@example.com', 'Information');
  36. // $mail->addCC('cc@example.com');
  37. // $mail->addBCC('bcc@example.com');
  38.  
  39. //Attachments
  40. // $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
  41. // $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
  42.  
  43. //Content
  44. $mail->isHTML(true); // Set email format to HTML
  45. $mail->Subject = 'Here is the subject';
  46. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  47. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  48.  
  49. $mail->send();
  50. echo 'Message has been sent';
  51.  
  52. }catch (Exception $e) {
  53. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  54. }
  55.  
  56. }
  57.  
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement