mail.phps 1.0 KB

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