Need help coding a button switch relay

First, congratulations for posting your code properly!

  1. The way you have it coded it implies you have the button wired to ground with an external pull up resistor. If that is not the case there is a problem with your button. I would suggest wiring the button to ground and using the internal pull up resistor.
  2. You are basing your conditionals on whether the button IS pressed and not when the button BECOMES pressed. You want to know when the button becomes pressed to start a timer. See the following tutorial: StateChangeDetection
  3. In the code below I assume you think both the digitalWrite() and delay() calls only execute if the conditional is true. That is not the case below. Only the digitalWrite() executes as part of the conditional. The delay() calls are executing for every loop().
if (buttonState == LOW)
  digitalWrite(relayPin,LOW);
  delay(3000); 
if (buttonState == HIGH)  
  digitalWrite(relayPin,HIGH);
 delay(25000);

I think what you intended was this:

if (buttonState == LOW)
{
  digitalWrite(relayPin,LOW);
  delay(3000); 
}
if (buttonState == HIGH)  
{
  digitalWrite(relayPin,HIGH);
  delay(25000);
}
  1. I don't recommend delay() to time the relay. It will cause the button to not be read during the relay activation because the program is stuck not doing anything during the delay. I recommend using millis() to time the relay. Look at these tutorials:
    Example-code for timing based on millis()
    BlinkWithoutDelay