The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Tell a friend with teaxtarea!
Discuss Tell a friend with teaxtarea! in the PHP Development forum on Dev Shed. Tell a friend with teaxtarea! PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 20th, 2012, 02:35 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 4
Time spent in forums: 54 m 18 sec
Reputation Power: 0
|
|
|
Tell a friend with teaxtarea!
Does anybody know how to implement in this form <textarea> ?
Code:
http://imgur.com/dt1ap
PHP Code:
<?php
if (isset($_POST['Submit'])) {
// This will check to see if the form has been submitted
$senders_email = $_POST['your_email'];
// The person who is submitting the form
$recipient_friend = $_POST['friend_email'];
// The forms recipient
mail($recipient_friend,"A message from $senders_email", "Dear $recipient_friend,\n\nYour friend $senders_email, found our site very useful, and thought you would be interested.\n\nPlease follow the link to view our site:\n(URL address blocked: See forum rules)\n\nThank You\n\nThe your_sites_address.com", 'From: "your_site" <your_email.com>');
if (isset($_POST['your_email'])) {
echo "<br>Your friend $recipient_friend has been contacted <br><br>Thank you $senders_email";
}}
?>
Code:
<form action="tell_a_friend.php" method="POST">
<fieldset>
<legend>Tell a friend</legend><br />
Your email<br />
<input type="text" name="your_email" value="Your email" /><br /><br />
Your Friends email<br />
<input type="text" name="friend_email" value="Your friends email" />
<input type="Submit" value="Tell a friend" name="Submit" />
</fieldset>
</form>
|

December 20th, 2012, 04:41 AM
|
|
|
|
Looks like you already have. What is not working?
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.
|

December 20th, 2012, 07:09 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 4
Time spent in forums: 54 m 18 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by gw1500se Looks like you already have. What is not working? |
yes in html I know how to add this field but I do not know how to include its value in the email (php)
|

December 20th, 2012, 07:14 AM
|
|
|
|
The same way you include any other value. You use $_POST with the name of the textarea (which you don't seem to have in your form).
|

December 20th, 2012, 07:30 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
Look at what you have:
<input type="text" name="your_email" value="Your email" /><br /><br />
Then in PHP:
$senders_email = $_POST['your_email'];
Do you see how the input name is the same as the post array key? That's how you do it. Give your input a name.
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|

December 20th, 2012, 07:51 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 4
Time spent in forums: 54 m 18 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by ManiacDan Look at what you have:
<input type="text" name="your_email" value="Your email" /><br /><br />
Then in PHP:
$senders_email = $_POST['your_email'];
Do you see how the input name is the same as the post array key? That's how you do it. Give your input a name. |
I have tried to do that but it doesn't work for me
my version ():
I includet in html:
Code:
<textarea id="message" name="url">
Your text here
</textarea>
And in php I included this code:
Code:
$message = $_POST['url'];
then I included this in mail body
Code:
mail($recipient_friend,"A message from $senders_email", "Dear $recipient_friend,\n\nYour friend $senders_email, $message found our site very useful, and thought you would be interested.\n\nPlease follow the link to view our site:\n(URL address blocked: See forum rules)\n\nThank You\n\nThe your_sites_address.com", 'From: "your_site" <your_email.com>');
But it doesn't work
|

December 20th, 2012, 08:39 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
This is how you debug:
1) Are you sure the textarea is named properly and properly formed? Inspect it in firebug or chrome inspector to see if those tools have a "name" attribute with "url" as the value.
2) If it is, make sure it's being included in the POST data. print_r($_POST) in your PHP to dump the post data to the screen, see if it's present.
3) If it's present, ensure your variable assignment is working. Echo $message before sending the email.
4) If $message is correct, double-check the spelling of your variables inside the mail() call. If they're correct, pull the entire email body out of that function call and make it a variable, then echo THAT to the screen as well.
|

December 20th, 2012, 10:09 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 4
Time spent in forums: 54 m 18 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by ManiacDan This is how you debug:
1) Are you sure the textarea is named properly and properly formed? Inspect it in firebug or chrome inspector to see if those tools have a "name" attribute with "url" as the value.
2) If it is, make sure it's being included in the POST data. print_r($_POST) in your PHP to dump the post data to the screen, see if it's present.
3) If it's present, ensure your variable assignment is working. Echo $message before sending the email.
4) If $message is correct, double-check the spelling of your variables inside the mail() call. If they're correct, pull the entire email body out of that function call and make it a variable, then echo THAT to the screen as well. |
Code:
data. print_r($_POST)
where should I search for it?
Can you please edit the existing code to make it work ok and submit here ? There are hundreds of scripts on the internet with tell a friend functions but they either do not work or doesn't have a text area. This one is perfect one it is so speedy and do not fall in spam box.
Please modify it for us , newbies 
|

December 20th, 2012, 10:30 AM
|
|
|
Since you didn't post existing code we can't. However, 'data.' is the end of ManiacDan's prevous sentence not part of the code. Anywhere before your first use of $_POST add this:
PHP Code:
echo "<pre>";
print_r($_POST);
echo "</pre>";
|

December 20th, 2012, 10:42 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
Since you got to step 2, I assume you did step 1. gw is correct, I meant the code he said. Then, what you would search for, is the variable in question. In this case, an entry for "url" in the resulting printed array.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|