欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

使用PHPMailer来发送带图片的 HTML Emails

程序员文章站 2022-05-24 10:16:54
...
  1. require("class.phpmailer.php");
  2. $mail = new PHPMailer();$mail = new PHPMailer();
  3. $mail->IsSMTP();
  4. $mail->Host = "smtp1.example.com;smtp2.example.com";
  5. $mail->SMTPAuth = true;
  6. $mail->Username = 'smtpusername';
  7. $mail->Password = 'smtppassword';
  8. $mail->From="mailer@example.com";
  9. $mail->FromName="My site's mailer";
  10. $mail->Sender="mailer@example.com";
  11. $mail->AddReplyTo("replies@example.com", "Replies for my site");
  12. $mail->AddAddress("email@example.com");
  13. $mail->Subject = "Test 1";
  14. $mail->IsHTML(true);
  15. $mail->AddEmbeddedImage('logo.jpg', 'logoimg', 'logo.jpg'); // attach file logo.jpg, and later link to it using identfier logoimg
  16. $mail->Body = "

    Test 1 of PHPMailer html

  17. This is a test picture: 使用PHPMailer来发送带图片的 HTML Emails

    ";
  18. $mail->AltBody="This is text only alternative body.";
  19. if(!$mail->Send())
  20. {
  21. echo "Error sending: " . $mail->ErrorInfo;;
  22. }
  23. else
  24. {
  25. echo "Letter is sent";
  26. }
  27. ?>
复制代码

PHPMailer, HTML, Emails