Small problem with my PHP Form- HEELP!

They have: 15 posts

Joined: Nov 2003

Hi everyone. I am new here.

I am having trouble with a form on my webstie which i just made. I want a user to enter their email into this box which will then be emailed to me to be added onto a newsletter list. OK I CAN DO THIS! But i am having trouble with getting the unsubscribe function. Currently when you subscribe it says
"Thanks, your email $subscribe has been added to the news list" and when you unsibscribe it says "Thanks, your email $subscribe has been added to the news list" although all they do is just send the person email to me.

So, can someone help my tweek my html and php file. So people can unsubcribe, and when they do it says that their email address has been unsubsribed?

I have copied the offending code below.

CODE FROM HTML WEBSITE

 Submit

CODE FROM PHP FILE
<?
$subscribe=$_POST['subscribe'];
$to="[email protected]";
$message="Some has just requested to be put on your news list. Their e-mail address was: $email";
if(mail($to,"News List Request","From: $subscribe\n")) {
echo "Thanks, your email $subscribe has been added to the news list.";
echo 'Click here to return to Alpineski.co.nz me';
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
?>

You can also see the failed script in action at alpineski.co.nz/newslist.html - at the bottom of the page.

Thanks!

They have: 15 posts

Joined: Nov 2003

Hey, I have done some more reasearching and this is what i would like to add.

$this = "box checked";
$that = "box inchecked";

if ($this == $that){
echo "Thanks, your email: $email has been added to the Newsletter List!";
} else {
echo "Your email $email has been taken off the newsletter list!";
}

so.. how do i fit it in without making it al do nothing~!!

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

What you really want is to do a conditional statement like this:

<?php
if (isset($unsubscribe)) {
   
// perform the actions to unsubscribe the user
    // report that the user is unsubscribed
   
echo \"You've successfully unsubscribed -- we're going to miss you!\";
    }

if (isset(
$subscribe) && $subscribe != '') {
    // you should make sure the email is right, too
    // perform the actions to subscribe the person to your list
    // let them know you were able to do so
    echo \"Thanks for subscribing! We love you, let's get married.\";
    }
?>

Of course, there are some issues with form validation in there, and such and it looks like it just emails you the information -- why not get a good PHP list manager?

They have: 15 posts

Joined: Nov 2003

Hey, thanks for that! Wink

Can you recommend any good PHP mailers that are avialable for free and easy to set up for people like me?

They have: 15 posts

Joined: Nov 2003

Hey Suzanne,
I added the code to the PHP file but now it just goes blank. It seems that the new code by itself wont email their email to me but the old one wont tell me if they are unsubsribed. SO i really need a mix between the two. The code that i have now is

<?php
$subscribe
=$_POST['subscribe'];
$to=\"[email protected]\";
$message=\"Someone has just requested to be put on your news list. Their e-mail address was: $email\";


if(mail(
$to,\"News List Request\",\"From: $subscribe\n\")) {
echo \"Thanks, your email
$subscribe has been added to the news list.\";
echo '<a href=\"http://www.alpineski.co.nz\">Click here to return to Alpineski.co.nz <img src=\"http://www.alpineski.co.nz/images/rupe.jpg\" width=\"\" height=\"\" alt=\"me\" border=\"0\"></a>';
} else {
echo \"There was a problem wih the email address. Please check that you filled in the form correctly.<a href=\"http://www.alpineski.co.nz/contact.html\">Click here to return to the contact page\";
}



if (isset(
$unsubscribe)) {
    // perform the actions to unsubscribe the user
    // report that the user is unsubscribed
    echo \"You've successfully unsubscribed -- we're going to miss you!\";
    }

if (isset(
$subscribe) && $subscribe != '') {
    // you should make sure the email is right, too
    // perform the actions to subscribe the person to your list
    // let them know you were able to do so
    echo \"Thanks for subscribing! We love you, let's get married.\";
    }
?>

If you could help me i would be very grateful. Smiling

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

I'm sorry, Alpine, you aren't familiar with PHP, then? This isn't your own code?

The comments in the sample meant you should put in your information. This script isn't very good, really -- there are many holes and bugs in it!

<?php

$subscribe
=$_POST['subscribe'];
$to=\"[email protected]\";
$unsubmessage = \"Remove $subscribe from the list.\";
$message=\"Someone has just requested to be put on your news list. Their e-mail address was: $subscribe\";

if (isset(
$unsubscribe)) { 
    // perform the actions to unsubscribe the user 
    if (mail(
$to,\"News List Removal Request\",$unsubmessage,\"From: $subscribe\n\")) {
        echo \"Thanks, your email
$subscribe has been removed from the news list.\";
        echo '<a href=\"http://www.alpineski.co.nz\">Click here to return to Alpineski.co.nz <img src=\"http://www.alpineski.co.nz/images/rupe.jpg\" width=\"\" height=\"\" alt=\"me\" border=\"0\"></a>';
    } else {
        // note: this doesn't actually mean there is a problem with the subscriber's email at all -- only that the mail wasn't sent. Don't blame the user!
        echo \"There was a problem with the email address and we were unable to remove it from the news list. Please check that you filled in the form correctly.<a href=\"http://www.alpineski.co.nz/contact.html\">Click here to return to the contact page\";
    }
    // if you do this like this, you'll have the user getting a message that they were not unsubscribed and that they were at the same time -- this is not good!
    // report that the user is unsubscribed 
    echo \"You've successfully unsubscribed -- we're going to miss you!\"; 


if (isset(
$subscribe) && $subscribe != '') { 
    // you should make sure the email is right, too 
    // perform the actions to subscribe the person to your list 
    if (mail(
$to,\"News List Request\",$message,\"From: $subscribe\n\")) { 
        echo \"Thanks, your email
$subscribe has been added to the news list.\";
        echo '<a href=\"http://www.alpineski.co.nz\">Click here to return to Alpineski.co.nz <img src=\"http://www.alpineski.co.nz/images/rupe.jpg\" width=\"\" height=\"\" alt=\"me\" border=\"0\"></a>';
    } else {
        echo \"There was a problem wih the email address. Please check that you filled in the form correctly.<a href=\"http://www.alpineski.co.nz/contact.html\">Click here to return to the contact page\";
    }
   
    // let them know you were able to do so 
    echo \"Thanks for subscribing! We love you, let's get married.\"; 

?>

This is still really poor scripting, though -- you would be better to get an already built php mailing list program instead of this.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

They have: 15 posts

Joined: Nov 2003

Cool, Thanks Suzanne,
BTW I got the script from a tutorial and then tried to customize it myself.... then things started to go wrong Sad

Anyway thanks!

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

heh, well it's a good start -- why not try the tutorial again and break it down into parts with comments? Then you'll be able to see the holes and fill them in! Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.