PageRenderTime 27ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/ collman/mail_accession.php

http://collman.googlecode.com/
PHP | 197 lines | 81 code | 32 blank | 84 comment | 11 complexity | f0072ef430612f9935d98dda73ea3fa0 MD5 | raw file
  1. <?php
  2. //=========== HEADER STUFF ========
  3. $Title = "";
  4. $PageName = "";
  5. require ("ta_config.inc");
  6. require("ta_header.inc");
  7. require("ta_opendb.inc");
  8. echo "<h4>Acknowledging accession by e-mail</h4>";
  9. $accessionNumber =$_REQUEST['accessionNumber'];
  10. $donor = $_REQUEST['donor'];
  11. $sqlstring="Select names.email, names.lastName FROM accessions INNER JOIN names ON accessions.donor = names.name WHERE accessions.donor = '$donor'";
  12. $sql=mysqli_query($dbcnx,$sqlstring);
  13. if($row = mysqli_fetch_row($sql)){
  14. $recipient = "$row[0]";
  15. $lastname = "$row[1]";
  16. }
  17. else {
  18. echo "No kidding! This person does not have an e-mail"; //Should be fixed with AJAX on accession form itself!
  19. exit;
  20. }
  21. if($MAIL_SERVICE = "smtp") {
  22. ////////////////////////////////////
  23. // USING SMTP W/O AUTHORISATION //
  24. ////////////////////////////////////
  25. ini_set ('SMTP', $MAIL_SERVER );
  26. // The message
  27. $message = "Dear Dr. $lastname <br/> We gratefully acknowledge your donation of some dead fish, registered as Acccession $accessionNumber.<br/>Yours sincerely,<br/>$CURATOR.";
  28. echo wordwrap("<p>Acknowledgement email has been sent to $donor ($recipient):</p><p>$message</p>");
  29. // Your email address
  30. $myemail = $session->email;
  31. // The subject
  32. $subject = "Acknowledgement of receipt of $accessionNumber";
  33. //Send the mail
  34. mail($recipient, $subject, $message, "From: $myemail") or die("Unable to send message");
  35. //if all is well
  36. echo wordwrap("<p>Acknowledgement email has been sent to $donor ($recipient):</p><p>$message</p>",60);
  37. } // IF $MAIL_SERVICE = "smtp"
  38. if($MAIL_SERVICE == "sendmail") {
  39. /////////////////////////////////
  40. // USING LINUX WITH SENDMAIL //
  41. /////////////////////////////////
  42. ini_set('sendmail_path', $MAILSERVER);
  43. $accessionNumber =$_REQUEST['accessionNumber'];
  44. $donor = $_REQUEST['donor'];
  45. // Your email address
  46. $myemail = $session->email;;
  47. // The subject
  48. $subject = "Receipt of $accessionNumber";
  49. // The message
  50. $message = "Enter your message here";
  51. mail($recipient, $subject, $message, "From: $myemail");
  52. echo "The email has been sent.";
  53. } // if $MAIL_SERVICE = sendmail
  54. if ($MAIL_SERVICE == "Outlook") {
  55. ////////////////////////////////////////////////
  56. // Outlook variant in testing //
  57. // COM-Based outlook use for sending mail //
  58. // Adapted from tuturial by Bogomil Shopov //
  59. // http://www.howtodothings.com/computers/ //
  60. // a1059-how-to-send-e-mail-using-php //
  61. // -com-functions.html //
  62. ////////////////////////////////////////////////
  63. echo "Starting<br />";
  64. $objApp = new COM("Outlook.Application");
  65. $app->Visible = true;
  66. $namespace = $objApp->GetNamespace("MAPI");
  67. echo "Mapi<br />";
  68. $myItem = $objApp->CreateItem(olMailItem);
  69. echo "MailItem<br />";
  70. $a=$myItem->Recipients->Add("sven.kullander@nrm.se");
  71. echo "Add<br />";
  72. $myItem->Subject="This is a test";
  73. echo "Subject<br />",
  74. $myItem->Body="This is a Body Section now.....!";
  75. echo "Body<br />";
  76. // $attachments = $myItem->{"attachments"};
  77. // $attachment = $attachments->Add("c:\\perl\\progs\\outlook.pl");
  78. $myItem->Display();
  79. echo "Display<br />";
  80. $myItem->Send();
  81. echo "Sent<br />";
  82. } // IF $MAIL_SERVICE = Outlook
  83. /*
  84. The explanation
  85. $objApp = new COM("Outlook.Application");
  86. In the first line we create a instance of the COM object (in this case your
  87. Outlook Application)
  88. If you have installed MS Outlook, in your Windows registry exists a key named
  89. Outlook.Application
  90. Start Regedit.exe and explore the HKEY_CLASSES_ROOT . There is your Com objects.
  91. $myItem = $objApp->CreateItem(olMailItem);
  92. Creates new MailItem (new Mail)
  93. $a=$myItem->Recipients->Add("admin@purplerain.org");
  94. Adding the Recipient element of MailItem
  95. This will be your recipient
  96. $myItem->Subject="This
  97. is a test";
  98. Adding Subject element
  99. This will be your subject
  100. $myItem->Body="This is
  101. a Body Section now.....!";
  102. Adding the Body element of MailItem
  103. This will be your message
  104. $myItem->Display();
  105. If you want see your Outlook Mail dialog add this line in the script ,else just
  106. comment it!
  107. $myItem->Send();
  108. Send the message using your DEFAULT Outlook account.
  109. */
  110. if ($MAIL_SERVICE == "MAPI") {
  111. /////////////////////////////////
  112. // UNTESTED MAPI WITH EXCHANGE //
  113. /////////////////////////////////
  114. #New MAPI session...
  115. $session = new COM("MAPI.Session");
  116. #Login
  117. $strProfileInfo = "exchange_server" . chr(10) . "exchange_user";
  118. $session->Logon("", "", 0, 1, 0, 1, $strProfileInfo);
  119. # New message...
  120. $msg = $session->Outbox->Messages->Add();
  121. $msg->Subject = "Subject";
  122. $msg->Text = "body";
  123. #set recipients...
  124. $rcpts = $msg->Recipients;
  125. $rcpts->AddMultiple("toto@toto.com", 1); #To...
  126. $rcpts->AddMultiple("titi@titi.com", 2); #Cc...
  127. $rcpts->AddMultiple("tutu@tutu.com", 3); #Bcc...
  128. # Resolve senders
  129. $rcpts->Resolve();
  130. #Send message
  131. $msg->Send();
  132. #Logoff
  133. $session->Logoff();
  134. #Cleanup
  135. if($msg!=null) {
  136. $msg->Release();
  137. $msg = null;
  138. }
  139. if($session!=null) {
  140. $session->Release();
  141. $session = null;
  142. }
  143. } //if $MAIL_SERVICE=MAPI
  144. ?>