Hi There,
Ok I have tried this for myself... What do I need to edit in the code for it to send me an email... When someone subscribes? or Leaves? Here is my tester page:
http://www.curiousclothing.com/email_form_test.php
Printable View
Hi There,
Ok I have tried this for myself... What do I need to edit in the code for it to send me an email... When someone subscribes? or Leaves? Here is my tester page:
http://www.curiousclothing.com/email_form_test.php
You can take out my two comments in the script... if you want, that is.
Does it seem to work for you? :)
Sure... you can do that. I'm no expert with the mail function.
Here's a possible version... look for "mail" at php.net if you want something else...
mail("your@email.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.");
(it's mail(to, subject, message))
I *think* that will work, but I've had problems with the function before... fairly complex in some ways. you can add more, but in this case, its just a note to you, so probably fine.PHP Code:<?php
if ($email = stripslashes($_POST['email'])) {
$filename = "emails.phplist";
$filecontents = @file_get_contents($filename);
if ($_POST['choice'] == "join") {
if (strpos($filecontents) != "") break;
if (strlen($filecontents) > 0) $comma = ", ";
$add = $comma.$email;
$emails = $filecontents.$add;
$file = @fopen($filename, "w+");
@fwrite($file, $emails);
@fclose($file);
$message = "Your email was added to the mailing list.".
"<br>Redirecting to the last page.";
}
elseif ($_POST['choice'] == "leave") {
$edited = str_replace($email,"",$filecontents);
$file = @fopen($filename, "w+");
@fwrite($file, $edited);
@fclose($file);
$message = "Your email was removed from the mailing list.".
"<br>Redirecting to the last page.";
}
////ADD BELOW
mail("your@email.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.");
////ADD ABOVE
}
if ($message != "") die("<html><head>".
"<meta http-equiv=\"refresh\" content=\"3;url=\">".
"</head><body>".$message."</body></html>");
?>
I tried this version but the email never actually comes to me... Also says there is a line error code... Another thing is when they click submit is it possible to take it to the original page but just remove the form field and instead say your email has been added/removed?
With the previous code... What was it actually doing? was this creating a database of emails?
they are the same... the email is now added to the code above, but it's the same code.
it saves the emails to a text file, emails.phplist (don't be confused by the file extension... they don't mean anything... it's a text file).
well.... the redirect accomplishes that. If you remove the option to change, then you're not letting them leave the list, or join back up if they left.
Hmm... I suppose it's not that complex.
I think that should work.PHP Code:<?php
if ($email = stripslashes($_POST['email'])) {
$filename = "emails.phplist";
$filecontents = @file_get_contents($filename);
if ($_POST['choice'] == "join") {
if (strpos($filecontents) != "") break;
if (strlen($filecontents) > 0) $comma = ", ";
$add = $comma.$email;
$emails = $filecontents.$add;
$file = @fopen($filename, "w+");
@fwrite($file, $emails);
@fclose($file);
$message = "Your email was added to the mailing list.".
"<br>Redirecting to the last page.";
}
elseif ($_POST['choice'] == "leave") {
$edited = str_replace($email,"",$filecontents);
$file = @fopen($filename, "w+");
@fwrite($file, $edited);
@fclose($file);
$message = "Your email was removed from the mailing list.".
"<br>Redirecting to the last page.";
}
mail("your@email.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.");
}
?>
//YOUR HTML HERE
<?php if ($message != "") { echo $message; }
else { ?>
<form action="" method="post">
Join our newsletter!<br>
Email: <input type="text" name="email"><br>
<select name="choice">
<option value="join">Join</option>
<option value="leave">Leave</option>
</select>mailing list.<br>
<input type="Submit" value="Go!">
</form><?php } ?>
//THE REST OF YOUR HTML HERE
Dunno about the mail thing. some servers vary. Let's see if anyone else knows... I've never really understood the ins and outs of that function.
It sent me the email but just stayed on the redirect page with thisShould I just have 2 pages one saying "your now on the subscribtion list" and the other saying "you have been removed from the subscription list"... And then it loads either one depending?Quote:
Warning: Wrong parameter count for strpos() in /home/virtual/site750/fst/var/www/html/email_form_test.php on line 6
Your email was added to the mailing list.
Redirecting to the last page.
Also the email comes from Apache, any way to make it come from the person who emailed it? Or is that impossible?
I guess similar to this: http://www.php-scripts.com/
Actually any ideas hwo this one works?
http://www.akina.com.au/joinus.php
http://www.akina.com.au/joinus_thankyou.php
hmmm... if you put an @ symbol before a function, it will suppress warnings...
if (@strpos($filecontents) != "") break;
if (@strlen($filecontents) > 0) $comma = ", ";
However, I think I didn't do that correctly...
yeah... here... sorry:
if (strpos($filecontents, $email) != "") break;
if (strlen($filecontents, $email) > 0) $comma = ", ";
The example you posted... it just goes to a different page. I assumed that this was going to be placed ON a page, like www.theforce.net -- look on the right, about 3/5 of the way down.
If this is JUST a page with the form on it, like one you'd get to by clicking a a link to "join the newsletter"... seems like extra work, I'd say put it on the main page.
However... if you want that, then make the action of the form be the second page, and have the php at the top of that second page. That would work fine.
that's what the example you posted does.
Yeah... the php-scripts site... same as mine... its embedded on the page. that makes more sense to me. And, the way I have it setup, it'll just submit, display a message, and redirect back to the main site. (or you can skip the redirect/message page, like we've been talking about).
I agree with you definitely better going this way... It still has issues though: http://www.curiousclothing.com/email_form_test.php... I'm also a bit confused I think it'd be better once it eventually redirects to the page if the submit and email was all gone and in its place just had thank you for submitting... I'm thinking that some people might try again, you know what I mean?
You changed both lines?
True... the newest code I gave you should avoid that.