sendmail.phps 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * This example shows sending a message using a local sendmail binary.
  4. */
  5. require '../PHPMailerAutoload.php';
  6. //Create a new PHPMailer instance
  7. $mail = new PHPMailer;
  8. // Set PHPMailer to use the sendmail transport
  9. $mail->isSendmail();
  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 sendmail 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. }