IT Knowledge Base

~ Without sacrifice, there can be no victory ~

發佈日期:

分類:

如何自訂phpList設定(4)

今天要做的工作,是要求在用戶電郵中,新增一URL,連到phplist作訂閱通訊之用。

最初的想法是,只需要用戶直接點選URL,便直接完成訂閱。但因考慮到除用戶電郵外,還需要輸入用戶姓名,為令到用戶知道將會使用到的姓名,固點選URL,會跳出另一版面,代用戶決定之後,再按『訂閱』,才會完成整個過程。

假設phplist是安裝在以下環境下。
伺服器地址:http://192.168.0.100
phplist安裝位置:http://192.168.0.100/mailing/
phplist內通訊數目:1個
phplist內通訊名稱:News from 192.168.0.100
phplist內需輸入屬性(attribute)名稱:Name
phplist內完成訂閱後動作:返回本頁

只需要在電郵中,加入以下類似URL,指到以下檔案內容即可。其中email是用戶電郵,name是用戶姓名,email_subscribe.php是以下內容的檔案名稱。
http://192.168.0.100/email_subscribe.php?email=user1@gmail.com&name=user1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Sign phplist by URL</title>

<script type="text/javascript">
function checkform() {
document.subscribeform.emailconfirm.value = document.subscribeform.email.value;
}
</script>

<style type="text/css">
.content_1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 11pt;
}
.content_2 {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}
</style>

<head></head>
<body>

<?php
$email = $_GET["email"];
$name = $_GET["name"];
$p = $_GET["p"];
switch ($p) {
case "unsubscribed":
echo '<p class="content_2">You have successfully unsubscribed from our mailing list.<br>A confirmation mail will be sent to you soon.</p>';
break;
case "subscribed":
echo '<p class="content_2">Dear '.$name.':</p><p class="content_2">You have successfully subscribed to our mailing list.<br>A confirmation mail will be sent to you soon.</p>';
break;
case "alreadyunsub":
echo '<p class="content_2">You have already unsubscribed from our mailing list.</p>';
break;
case "usernotfound":
echo '<p class="content_2">You have not subscribed to our mailing list.</p>';
break;
case "":
echo '<p class="content_1">Thank you for interesting our newsletter.</p>';
echo '<form method="post" name="subscribeform" action="/mailing/?p=subscribe" onSubmit="return checkform()">';
echo '<p class="content_2">Your email address: <input type="text" name="email" value="'.$email.'" size="30"></p>';
echo '<input type="hidden" name="emailconfirm" size="30">';
echo '<p class="content_2">Your name: <input type="text" name="attribute1" size="20" value="'.$name.'"></p>';
echo '<input type="hidden" name="htmlemail" value="1"/>';
echo '<input type="hidden" name="list[1]" value="signup">';
echo '<input type="hidden" name="listname[1]" value="News from 192.168.0.100"/>';
echo '<p class="content_2"><input type=submit name="subscribe" value="Subscribe"></p>';
echo '</form>';
break;
}
?>

</body>
</html>

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *