• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

Use mail.php send mail but no subject.

Scheduled Pinned Locked Moved General pfSense Questions
3 Posts 2 Posters 102 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    akong77
    last edited by Apr 6, 2025, 2:59 AM

    Hello
    I has use follow script to get new pppoe ip address.

    #!/bin/sh
    
    # 設定 PPPoE 介面名稱 (請確認 pfSense 上的名稱,可能是 pppoe0)
    PPPOE_IF="pppoe0"
    
    # 設定紀錄檔
    IP_FILE="/root/current_pppoe_ip.txt"
    LOG_FILE="/root/ip_change.log"
    
    # 取得 PPPoE 的外部 IP
    CURRENT_IP=$(ifconfig $PPPOE_IF | grep 'inet ' | awk '{print $2}')
    
    # 確保有抓到 IP,否則跳出
    if [ -z "$CURRENT_IP" ]; then
        echo "$(date) - Failed to get PPPoE IP" >> "$LOG_FILE"
        exit 1
    fi
    
    # 如果檔案不存在,則建立它
    if [ ! -f "$IP_FILE" ]; then
        echo "$CURRENT_IP" > "$IP_FILE"
    fi
    
    # 讀取上次的 IP
    LAST_IP=$(cat "$IP_FILE")
    
    # 檢查 IP 是否變更
    if [ "$CURRENT_IP" != "$LAST_IP" ]; then
        # 記錄變更
        echo "$(date) - IP changed from $LAST_IP to $CURRENT_IP" >> "$LOG_FILE"
    
        # 使用 pfSense 設定的通知 Email 發送通知
        echo "New PPPoE IP: $CURRENT_IP (Previous: $LAST_IP)" | /usr/local/bin/mail.php -s "pfSense PPPoE IP Change Alert"
    
        # 更新紀錄檔
        echo "$CURRENT_IP" > "$IP_FILE"
    fi
    

    I use follow script to send mail to my email.

    echo "New PPPoE IP: $CURRENT_IP (Previous: $LAST_IP)" | /usr/local/bin/mail.php -s "pfSense PPPoE IP Change Alert"
    

    But I got mail have no subject.Have any error?

    P 1 Reply Last reply Apr 6, 2025, 7:04 AM Reply Quote 0
    • P
      patient0 @akong77
      last edited by Apr 6, 2025, 7:04 AM

      @akong77 said in Use mail.php send mail but no subject.:

      But I got mail have no subject.Have any error?

      The PHP manual for getopt states:

      "Note: Optional values do not accept " " (space) as a separator."

      And in the code "getopt("s::");" means '-s' is an optional value and there can't be a space between '-s' and "pfSense PPPoE IP Change Alert":

      /usr/local/bin/mail.php -s"pfSense PPPoE IP Change Alert"

      A 1 Reply Last reply Apr 6, 2025, 8:51 AM Reply Quote 0
      • A
        akong77 @patient0
        last edited by Apr 6, 2025, 8:51 AM

        @patient0
        Ohh.
        I got it.Thanks a lot.

        1 Reply Last reply Reply Quote 0
        3 out of 3
        • First post
          3/3
          Last post
        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
          This community forum collects and processes your personal information.
          consent.not_received