test_mail_advanced.php 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. <html>
  2. <head>
  3. <title>PHPMailer - Mail() advanced test</title>
  4. </head>
  5. <body>
  6. <?php
  7. require_once '../class.phpmailer.php';
  8. $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
  9. try {
  10. $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  11. $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
  12. $mail->SetFrom('name@yourdomain.com', 'First Last');
  13. $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  14. $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  15. $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  16. $mail->MsgHTML(file_get_contents('contents.html'));
  17. $mail->AddAttachment('images/phpmailer.gif'); // attachment
  18. $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
  19. $mail->Send();
  20. echo "Message Sent OK</p>\n";
  21. } catch (phpmailerException $e) {
  22. echo $e->errorMessage(); //Pretty error messages from PHPMailer
  23. } catch (Exception $e) {
  24. echo $e->getMessage(); //Boring error messages from anything else!
  25. }
  26. ?>
  27. </body>
  28. </html>