Current location: Hot Scripts Forums » Programming Languages » PHP » OK I give up - need help emailing form info


OK I give up - need help emailing form info

Reply
  #1 (permalink)  
Old 10-25-04, 08:50 PM
2jesters 2jesters is offline
Newbie Coder
 
Join Date: Oct 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy OK I give up - need help emailing form info

I'm adding a Newsletter/email subscription service to my web site. There will be list of newsletters from different authors. The visitor clicks on a checkbox next to the newsletter(s)/ezine(s) they are interested in and then at the bottom of the page they enter their name and email address, and of course click on the subscribe button.

I've got that part written in html and it works fine. Here's the basic code:

<td><form action="subscribe.php" method="post">
<p align = "left"><input type="checkbox" name = "email[]" value="somename@somewhere.com"> <font color="blue"><b>Newsletter Title</b></font> <br><font face="Verdana" size="2">Newsletter Description.</font></p><p align = "left"><input type="checkbox" name = "email[]" value="author@writer.com"> <font color="blue"><b>Newsletter Title</b></font> Newsletter Description.</font></p>
<center>
<p><font face="Verdana" size="2">Your Name: <br>
<input type="text" name="name" size="10"></font></p>
<p><font face="Verdana" size="2">Your Email:<br>
<input type="text" name="addy" size="10"></font></p>
<INPUT TYPE="submit" NAME="button" VALUE="Subscribe To Newsletter(s) Checked">
</center>
</FORM>

I wanted to use php for the form processing because of the array email[]. I've tried several things using the "foreach" loop, but can't make my "subscribe.php" file send the name and email address to the selected newsletter(s)' author(s). How do I do this in php? I'm not php literate, so any help would be appreciated.

Thanks,
2jesters
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-26-04, 03:17 AM
marklar's Avatar
marklar marklar is offline
Newbie Coder
 
Join Date: May 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
You do not need the square brackets [] because it will automatically be made into an array. You only need to put them in your HTML if you want to access the array using Javascript (see this thread if you're interested), in php the [] is NOT part of the name, even if they are part of the name in HTML. This test script should work:

<?php
if(isset($_POST['addy'])){
echo sizeof($_POST['email']);
$subs = $_POST['email'];
foreach($subs as $key => $value){
echo $value;
};
echo "DONE";
};
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-26-04, 09:57 AM
2jesters 2jesters is offline
Newbie Coder
 
Join Date: Oct 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Marklar,

I'll give that a try and let you know how it works.

Thanks again,
2jesters
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-26-04, 03:48 PM
2jesters 2jesters is offline
Newbie Coder
 
Join Date: Oct 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
marklar,

I've got everything working except the mail() function. The first parameter has to be a string. What do I need to do?

Here's my code:

<?php
$from = "subscribe@resourcesite.org";
$subject = "You've received another subscriber from Jesters Resource Site's eNewstand";
$message =
"$_POST[name] \n
$_POST[addy] \n\n";
$headers = "From: $from";
if(isset($_POST['addy'])){
echo sizeof($_POST['email']);
$subs = $_POST['email'];
mail($subs,$subject,$message,$headers);
foreach($subs as $key => $value){
echo $value;
};
echo "DONE";
};
?>


Thx
2jesters
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 10-26-04, 04:02 PM
bizzar528's Avatar
bizzar528 bizzar528 is offline
Community Liaison
 
Join Date: Sep 2004
Location: Pennsylvania, US
Posts: 1,551
Thanks: 2
Thanked 16 Times in 15 Posts
change

Code:
mail($subs,$subject,$message,$headers);
to

Code:
mail($from,$subject,$message,$headers);
Though the variables are misleading, I assume "subscribe@resourcesite.org" is the actual TO address.

reference -- http://us2.php.net/manual/en/function.mail.php (mail(TO, SUBJECT, MESSAGE, HEADERS)

Also, the

Code:
$headers = "From: $from";
should probably be:

Code:
$headers = "From: $_POST[addy]";
__________________
Yep, it's a signature...

Last edited by bizzar528; 10-26-04 at 04:05 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 10-26-04, 04:30 PM
2jesters 2jesters is offline
Newbie Coder
 
Join Date: Oct 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, but the TO address is from the array "email[]". We will be sending out the form info to newsletter authors selected by our visitors.

2jesters
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 10-26-04, 10:28 PM
sandal sandal is offline
New Member
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by 2jesters
Thanks, but the TO address is from the array "email[]". We will be sending out the form info to newsletter authors selected by our visitors.

2jesters

so you are going to send email to many addresses?
have you tried to use foreach[] function?

Code:
<?
// said that $addr mean array contains many address
foreach($addr as $to){
            mail($to,$subj,$msg,$header);
}
?>
hope it works
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 10-27-04, 02:09 AM
marklar's Avatar
marklar marklar is offline
Newbie Coder
 
Join Date: May 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
What Sandal said is correct except that in your code it will look like this:

foreach($subs as $key => $value){
mail($value,$subject,$message,$headers);
};

That will be the simplest way of doing things. For future reference you can use mail() to send to multiple addresses if you seperate each address with a semi-colon ; like this
$to ="address@domain.com; email@address.com; another@somewhere.com"

In addition you can send someone's real name like this:
$to="Steve Smith <address@domain.com>; Boris Becker <email@address.com>; Madonna <another@somewhere.com>"

Just remember not to send to things like test@somewhere.com while you are testing, you will never know if it went & people at that sort of address must get thousands of messages.

:I
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 10-27-04, 02:55 AM
moronovich moronovich is offline
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
What Sandal said is correct except that in your code it will look like this:

foreach($subs as $key => $value){
mail($value,$subject,$message,$headers);
};
no.. no... no.. sandal is right. php control 'foreach' with syntax "foreach($myArray as $myValue)" will return successive $myValue which each is the value of $myArray and not the array key. (please read the php doc or php source for this.. )

anyway, to use semicolon to send mail to some persons is +1 for me..
__________________
just an ignorant noob with moronic solution...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 10-27-04, 03:27 AM
marklar's Avatar
marklar marklar is offline
Newbie Coder
 
Join Date: May 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
I know it's not perfectly efficient but I posted it like that for 2 reasons:
1) It's exactly the same code as he already has, just moving the lines around.
2) It teaches dealing with associative arrays in the future eg, the email address as $key and the real name as $value.

I'm afraid I broke a rule I have "Don't post unless you are sure". The syntax I gave for mail() is wrong, this is correct:

$to = "mary@example.com" . ", " ; // note the comma not semi-colon
$to .= "kelly@example.com";

$headers = "To: Mary <mary@example.com>, Kelly <kelly@example.com>\r\n";
$headers .= "From: Birthday Reminder <birthday@example.com>\r\n";
$headers .= "Cc: birthdayarchive@example.com\r\n";
$headers .= "Bcc: birthdaycheck@example.com\r\n";

mail($to, $subject, $message, $headers);

Sorry about that, but I had just woken up.
:I
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting 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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
formmail problem gscraper Perl 12 08-27-04 04:06 AM
Adding to an existing PHP script to drop form info into an Excel ss jerryh0707 PHP 1 07-21-04 04:03 PM
Limit the form submission according to time bionicsamir PHP 7 05-10-04 12:10 AM
Emailing a form HUH? icesayain2k HTML/XHTML/XML 5 01-13-04 01:13 PM
SQL database registration form help vinhkhuong PHP 3 10-10-03 04:49 AM


All times are GMT -5. The time now is 09:19 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.