Test.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Heanup\Test;
  3. use PHPMailer\PHPMailer\Exception;
  4. use PHPMailer\PHPMailer\PHPMailer;
  5. use PHPUnit\Framework\TestCase;
  6. class Test extends TestCase
  7. {
  8. public function testCalculate()
  9. {
  10. $mail=new PHPMailer(true);
  11. try {
  12. //Server settings
  13. $mail->SMTPDebug = 2; // Enable verbose debug output
  14. $mail->isSMTP(); // Set mailer to use SMTP
  15. $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
  16. $mail->SMTPAuth = true; // Enable SMTP authentication
  17. $mail->Username = 'cdb@us.meitu.com'; // SMTP username
  18. $mail->Password = 'chendeben6485882'; // SMTP password
  19. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  20. $mail->Port = 587; // TCP port to connect to
  21. //Recipients
  22. $mail->setFrom('cdb@us.meitu.com', 'Heanup');
  23. // $mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
  24. // $mail->addAddress('ellen@example.com'); // Name is optional
  25. $mail->addReplyTo('cdb@us.meitu.com', 'Heanup');
  26. $mail->addCC('chendeben@qq.com');
  27. // $mail->addBCC('bcc@example.com');
  28. //Attachments
  29. // $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
  30. // $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
  31. //Content
  32. $mail->isHTML(true); // Set email format to HTML
  33. $mail->Subject = 'Here is the subject';
  34. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  35. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  36. $mail->send();
  37. echo 'Message has been sent';
  38. } catch (Exception $e) {
  39. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  40. }
  41. }
  42. }