invite.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // Require Composer's autoloader.
  3. require_once '../../vendor/autoload.php';
  4. // Require Composer's autoloader.
  5. use PHPMailer\PHPMailer\PHPMailer;
  6. use PHPMailer\PHPMailer\SMTP;
  7. use PHPMailer\PHPMailer\Exception;
  8. require_once '../config.php';
  9. require_once "../redis/function.php";
  10. require_once "../public/function.php";
  11. if (PHP_SAPI == "cli") {
  12. if ($argc == 2) {
  13. $email = $argv[1];
  14. $redis = redis_connect();
  15. if ($redis == false) {
  16. echo "no redis connect\n";
  17. exit;
  18. }
  19. $uuid= UUID::v4();
  20. $invitecode = "invitecode://".$uuid;
  21. $redis->set($invitecode,$email);
  22. $redis->expire($invitecode,7*20*3600);
  23. $SignUpLink="https://www.wikipali.org/ucenter/index.php?op=new&invite=".$uuid;
  24. $SignUpString="https://www.wikipali.org/ucenter/index.php?op=new&invite=".$uuid;
  25. // 打开文件并读取数据
  26. $irow=0;
  27. $strSubject = "";
  28. $strBody = "";
  29. if(($fp=fopen("invite_letter.html", "r"))!==FALSE){
  30. while(($data=fgets($fp))!==FALSE){
  31. $irow++;
  32. if($irow==1){
  33. $strSubject = $data;
  34. }else{
  35. $strBody .= $data;
  36. }
  37. }
  38. fclose($fp);
  39. echo "body load:";
  40. }
  41. else{
  42. echo "can not load body file. ";
  43. }
  44. $strBody = str_replace("%SignUpLink%",$SignUpLink,$body);
  45. $strBody = str_replace("%SignUpString%",$SignUpString,$body);
  46. //TODO sendmail
  47. //Create an instance; passing `true` enables exceptions
  48. $mail = new PHPMailer(true);
  49. try {
  50. //Server settings
  51. $mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
  52. $mail->isSMTP(); //Send using SMTP
  53. $mail->Host = Email["Host"]; //Set the SMTP server to send through
  54. $mail->SMTPAuth = Email["SMTPAuth"]; //Enable SMTP authentication
  55. $mail->Username = Email["Username"]; //SMTP username
  56. $mail->Password = Email["Password"]; //SMTP password
  57. $mail->SMTPSecure = Email["SMTPSecure"]; //Enable implicit TLS encryption
  58. $mail->Port = Email["Port"]; //TCP port to connect to 465; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
  59. //Recipients
  60. $mail->setFrom(Email["From"], Email["Sender"]);
  61. $mail->addAddress($email); //Add a recipient Name is optional
  62. //Attachments
  63. //$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
  64. //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
  65. //Content
  66. $mail->isHTML(true); //Set email format to HTML
  67. $mail->Subject = $strSubject;
  68. $mail->Body = $strBody;
  69. $mail->AltBody = $strBody;
  70. $mail->send();
  71. echo 'Message has been sent';
  72. } catch (Exception $e) {
  73. echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
  74. }
  75. }else{
  76. echo "email?";
  77. }
  78. }else{
  79. echo ":-)";
  80. }
  81. ?>