Jump to content


Photo

Help With PHP


  • Please log in to reply
7 replies to this topic

#1 chey

chey
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 03 July 2006 - 05:01 AM

hello, i need some help with PHP. in fact, i know NUTS about PHP, and my asp knowledge has been returned to my teacher 2 years ago.

anyway, i need some basics first. my aim is to configure a command in a form, and when the form is validated, to actually send my email add the contents of the form.

sounds a bit too much for a beginner, but can anyone help?

#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 03 July 2006 - 06:26 AM

Need more details about it.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#3 chey

chey
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 04 July 2006 - 01:50 AM

ok, right now i have this form here below...

Posted Image

and i just need to make sure when i click the 'subscribe' button, there would be an email sent to me.

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 04 July 2006 - 05:38 AM

okay your form should look something similar to this:
<form action = 'somewhere.php' method = 'post'>
   Name: <input type = 'text' name='name'><br>
   Email:  <input type = 'text' name='email'><br>
             <input type = 'submit' value='subscribe' name='submit'>
</form>

okay so in somewhere.php you would have this:

<?php
   if ($_POST['submit']) {
      mail ('youremailaddress.com','subject here','message here');
   }
?>

 
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 chey

chey
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 05 July 2006 - 04:27 AM

ok, i can understand that... but the problem is, currently the form is linked to a js, that is, when submit is clicked, the data inserted will go to a database through the js function which looks like this.

	function submitcombutton() {
		var form = document.mosForm;
				
		// do field validation
		if (form.name.value == "") {
			alert( "<?php echo _REGWARN_NAME;?>" );
		} else if (form.email.value == "") {
			alert( "<?php echo _REGWARN_MAIL;?>" );
		} else {
			form.submit();
		}
	}

then, this is the front end side

<form method="post" action="<?php echo sefRelToAbs('index.php?option=com_anjel&Itemid=' . $Itemid . '&action=unregistered&task=addUnregistered'); ?>" name="mosForm" >
 <table align="center" border="0" cellpadding="0" cellspacing="3">
	<tr>
		<td align="center"><?php echo _INPUT_NAME; ?></td>
		<td><input type="text" name="name" value="" class="inputbox" /></td>
	</tr>
	<tr>
		<td align="center"><?php echo _INPUT_EMAIL; ?></td>
		<td><input type="text" name="email" value="" class="inputbox" /></td>
	</tr> 
<?php
		foreach ($letters as $letter) {
?>
	<tr>
		<td align="right"><input type="checkbox" name="<?php echo $letter->id; ?>" value="1" class="inputbox" /></td>
		<td><span class="anjel_letter_names"><?php echo mosToolTip(addslashes(htmlentities($letter->list_desc)), addslashes(htmlentities($letter->list_name)), '', '', addslashes(htmlentities($letter->list_name)), '#', 1); ?></span></td>
		<td>&nbsp;</td>
	</tr>
<?php	
	 	} // end foreach
?>
    <tr> 
    	<td align="right"><input type="checkbox" name="receivehtml" value="1" class="inputbox" /></td>
        <td><?php echo _RECEIVE_HTML; ?></td>
    </tr> 
    <tr> 
                <td>&nbsp;</td>
      	 	<td><input type="button" value="<?php echo _SUBSCRIBE; ?>" class="button" onclick="submitcombutton()" /> 
		</td>
    </tr> 
 </table> 
 </form>

so how am i supposed to implement these 2 codings together?

#6 chey

chey
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 06 July 2006 - 10:38 AM

i managed to get the email to be generated. but now i need help with changing the name of the person sending the email. it gives me a funny address. how do i do so???

also, the 'message here', i want the message in my email to look something like this:

You have a new subscriber:
Name: (name entered)
Email: (email entered)

i am not good with this php stuff, but so far, the code was:

if ($result) {
	echo '<p>' . _UNREGISTEREDADDED . '</p>';

and i added
mail ('myemail','New Subscriber For Newsletter','You Have a New Unregistered Subscriber:<br /> Name:'name'<br /> Email:'email'<br />');

now, my problem is the last '', where that is what would appear in the email. so i need help with that only. the email is sent fine.
     

#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 06 July 2006 - 11:32 AM

The line you showed for the mail() function is incorrect. It is much better to put all the information into variables:
<?php
$to = 'your@email.address.here';
$subject = 'New Subscriber For Newsletter';
$body = "You Have a New Unregistered Subscriber:\n";
$body .= "Name: $nameEntered\n";
$body .= "Email: $emailEntered\n";
$headers = "From: $to\n";
mail($to,$subject,$body,$headers);
?>

Ken

#8 chey

chey
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 07 July 2006 - 02:52 AM

thanks a lot for you help! every thing goes thru, except the name now. *headdesks*

i really appreciate the help... though my php knowledge still sucks.

thanks once again ken :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users