mail.phps 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * This example shows sending a message using PHP's mail() function.
  4. */
  5. //Import the PHPMailer class into the global namespace
  6. use PHPMailer\PHPMailer\PHPMailer;
  7. require '../vendor/autoload.php';
  8. //Create a new PHPMailer instance
  9. $mail = new PHPMailer;
  10. //Set who the message is to be sent from
  11. $mail->setFrom('from@example.com', 'First Last');
  12. //Set an alternative reply-to address
  13. $mail->addReplyTo('replyto@example.com', 'First Last');
  14. //Set who the message is to be sent to
  15. $mail->addAddress('whoto@example.com', 'John Doe');
  16. //Set the subject line
  17. $mail->Subject = 'PHPMailer mail() test';
  18. //Read an HTML message body from an external file, convert referenced images to embedded,
  19. //convert HTML into a basic plain-text alternative body
  20. $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  21. //Replace the plain text body with one created manually
  22. $mail->AltBody = 'This is a plain-text message body';
  23. //Attach an image file
  24. $mail->addAttachment('images/phpmailer_mini.png');
  25. //send the message, check for errors
  26. if (!$mail->send()) {
  27. echo "Mailer Error: " . $mail->ErrorInfo;
  28. } else {
  29. echo "Message sent!";
  30. }