Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > subscribe.php

subscribe.php
Thread Tools
tumb
Forum Regular
Join Date: May 2004
Location: France
Status: Offline
Reply With Quote
Apr 4, 2012, 08:18 AM
 
Hello,
I have a webserver where PHP is installed.

On the footer of this page there is a newsletter subscription box on the right.

The code of the form is:
Code:
<form class="newsletter-form" action="subscribe.php" method="post" name="newsletter"> <fieldset> <input type="text" size="30" value="" id="newsletter-email" name="newsletter-email"> <input type="submit" class="newsletter-submit" name="send" value="Send"> </fieldset> </form>
And here is my PHP code:
Code:
<?php echo 'this is a test'; // test existance variable $mavariable = $HTTP_POST_VARS['newsletter-email']; echo $mavariable; //Si ok envoie mail //$TO = "[email protected]"; //$h = "From: " . $TO; //$subject = "Inscription newsletter "; //$message = $_POST['newsletter-email']; //mail($TO, $subject, $message, $h); //Header("Location: thanks.html"); ?>
Once the email is written, I'm redirected to thanks.html and I receive an email, but without the email address. Is there anyone who can give me the right php code ? I can pay for this work.

My iChat is [email protected]

thanks
     
andi*pandi
Moderator
Join Date: Jun 2000
Location: inside 128, north of 90
Status: Offline
Reply With Quote
Apr 4, 2012, 01:28 PM
 
You need another form field to gather their email address... I have the code at home.
     
tumb  (op)
Forum Regular
Join Date: May 2004
Location: France
Status: Offline
Reply With Quote
Apr 4, 2012, 03:28 PM
 
thanks a lot andi*pandi, would it be possible to send me the code by private message ?
you would help me a lot.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Apr 4, 2012, 03:57 PM
 
Yes, you need to collect the from address, and you should rewrite the following:

Code:
$mavariable = $HTTP_POST_VARS['newsletter-email'];
As:

Code:
$mavariable = $_POST['newsletter-email'];
As the other way is deprecated and will stop working soon, depending on what version of PHP you are running.

Your code should really include some checks to ensure that the from address is formatted correctly to prevent spam, and whatever you do do NOT change the code to allow the user to enter the "to" address the email is destined for in the public form, as this will open up the form for all kinds of spam abuse. IOW, leave recipient's address printed directly into the code as it is now.

Here is a simple check to ensure that the from address is formatted correctly:

Code:
<?php if (!preg_match('/^.+?@.+?\..+$/', $_POST['from-form-field'])) { // invalid email, do something } ?>
This is a very crude check, but it should help a little.
     
tumb  (op)
Forum Regular
Join Date: May 2004
Location: France
Status: Offline
Reply With Quote
Apr 5, 2012, 03:49 PM
 
Thanks guys, I figured it's actually a conflict with this js. Don't know yet where is the bug.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Apr 5, 2012, 04:24 PM
 
No it's not.

Code:
//$TO = "[email protected]"; //$h = "From: " . $TO;
Assuming that you have uncommented these two lines, you are setting the from address to be the same as the to address, there is absolutely no ambiguity about this.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 06:03 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,