Kaynağa Gözat

建立 发送邀请邮件功能

visuddhinanda 4 yıl önce
ebeveyn
işleme
293666fe69
2 değiştirilmiş dosya ile 97 ekleme ve 0 silme
  1. 93 0
      app/ucenter/invite.php
  2. 4 0
      app/ucenter/invite_letter.html

+ 93 - 0
app/ucenter/invite.php

@@ -0,0 +1,93 @@
+<?php
+// Require Composer's autoloader.
+require_once '../../vendor/autoload.php';
+
+// Require Composer's autoloader.
+use PHPMailer\PHPMailer\PHPMailer;
+use PHPMailer\PHPMailer\SMTP;
+use PHPMailer\PHPMailer\Exception;
+
+require_once '../config.php';
+require_once "../redis/function.php";
+require_once "../public/function.php";
+
+if (PHP_SAPI == "cli") {
+	if ($argc == 2) {
+		$email = $argv[1];
+        $redis = redis_connect();
+        if ($redis == false) {
+            echo "no redis connect\n";
+            exit;
+		}
+		$uuid= UUID::v4();
+		$invitecode = "invitecode://".$uuid;
+		$redis->set($invitecode,$email);
+		$redis->expire($invitecode,7*20*3600);
+		$SignUpLink="https://www.wikipali.org/ucenter/index.php?op=new&invite=".$uuid;
+		$SignUpString="https://www.wikipali.org/ucenter/index.php?op=new&invite=".$uuid;
+
+			// 打开文件并读取数据
+		$irow=0;
+		$strSubject = "";
+		$strBody = "";
+		if(($fp=fopen("invite_letter.html", "r"))!==FALSE){
+			while(($data=fgets($fp))!==FALSE){
+				$irow++;
+				if($irow==1){
+					$strSubject = $data; 
+				}else{
+					$strBody .= $data; 
+				}
+			}
+			fclose($fp);
+			echo "body load:";
+		}
+		else{
+			echo "can not load body file. ";
+		}
+
+		$strBody = str_replace("%SignUpLink%",$SignUpLink,$body);
+		$strBody = str_replace("%SignUpString%",$SignUpString,$body);
+
+		//TODO sendmail
+
+		//Create an instance; passing `true` enables exceptions
+		$mail = new PHPMailer(true);
+
+		try {
+			//Server settings
+			$mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
+			$mail->isSMTP();                                            //Send using SMTP
+			$mail->Host       = Email["Host"];                     //Set the SMTP server to send through
+			$mail->SMTPAuth   = Email["SMTPAuth"];                                   //Enable SMTP authentication
+			$mail->Username   = Email["Username"];                     //SMTP username
+			$mail->Password   = Email["Password"];                               //SMTP password
+			$mail->SMTPSecure = Email["SMTPSecure"];            //Enable implicit TLS encryption
+			$mail->Port       = Email["Port"];                                    //TCP port to connect to 465; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
+
+			//Recipients
+			$mail->setFrom(Email["From"], Email["Sender"]);
+			$mail->addAddress($email);     //Add a recipient Name is optional
+
+			//Attachments
+			//$mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
+			//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    //Optional name
+
+			//Content
+			$mail->isHTML(true);                                  //Set email format to HTML
+			$mail->Subject = $strSubject;
+			$mail->Body    = $strBody;
+			$mail->AltBody = $strBody;
+
+			$mail->send();
+			echo 'Message has been sent';
+		} catch (Exception $e) {
+			echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
+		}
+	}else{
+		echo "email?";
+	}
+}else{
+	echo ":-)";
+}
+?>

+ 4 - 0
app/ucenter/invite_letter.html

@@ -0,0 +1,4 @@
+wikipali 注册邀请
+点击此链接注册wikipali账号。此链接邀请只可以注册一个账户。有效期7天。
+<a href="%SignUpLink%">%SignUpString%</a><br>
+此邮件为系统自动发送,请勿回复。