Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include text from a textarea in an email message

Status
Not open for further replies.

BadChough

Programmer
Dec 20, 2007
137
GB
I think an element of my site used to work, but now doesn't.
I have a page in which an email message is constructed from text-data from an MYSQL dbase and includes input from a regular textarea called "comment". The email address "email1" is also input on the same page.
The problem is that the email arrives at its destination without the "comment" text from the textatrea.
Can you tell me what's going wrong, please. I quote what I hope is the relevant code.


PHP:
$org = $row_restSelect['cel_org'];
$tel =  $row_restSelect['cel_tel'];
$fax = $row_restSelect['cel_fax'];
$help = $row_restSelect['cel_hlp'];
$mail = $row_restSelect['cel_email'];
$web = $row_restSelect['cel_web'];
$address = $row_restSelect['cel_add'];
$details = strip_tags($row_restSelect['cel_blb']);
$handouts = $row_restSelect['cel_hndts'];

$message = "Message: $comment \n\n";	// Set up the email message to the client.
$message .= "Information about $org from [URL unfurl="true"]www.torbaymhresources.org.uk[/URL] website.\n\n";
$message .= "Contact Details: \n";
$message .= "Tel No. $tel \n";
$message .= "Fax No. $fax \n";
$message .= "Helpline: $help \n";
$message .= "Email: $mail \n";
$message .= "Website: $web \n\n";
$message .= "Postal Address: $address \n\n";
$message .= "Description of Service:\n $details \n\n";
$message .= "$handouts";

$inform_me = "Details of $org have been sent to someone"; // Set up the email to inform me of the information request.
// The emails:
if(mail("$email1", $org, $message, "From: [URL unfurl="true"]www.torbaymhresources.org.uk")[/URL] && mail("feedback@torbaymhresources.org.uk", $org,
$inform_me, "From: [URL unfurl="true"]www.torbaymhresources.org.uk"))[/URL]
{
header('location: [URL unfurl="true"]http://www.torbaymhresources.org.uk/feedback/email_redirect.php');//[/URL] redirect to page if email has been successfully sent
exit;
}else{
$error == '<p style="color:red;">An error occured, your email could not be sent. Please try
again</p>';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>Email  Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="fb.js"></script>
<link href="../css/mentalhealth_bx.css" rel="stylesheet" type="text/css" />
</head>
<body class="grey_bground" >

<form action="<?php echo $PHP_SELF; ?>" method="post" name="email1" id="email1">
<?php echo $error; ?>

Later we have:
Code:
    <tr>
      <td width="223" align="right"><p>&nbsp;</p>
      </td>
      <td colspan="3" valign="top">
        <textarea name="comment" cols="70" rows="2"
		onclick="document.email1.comment.value='';">Mouse-click to clear text - Write a message here if you wish.</textarea>
        <!-- javascript to clear text from text area onclick --></td>
    </tr>

and:
Code:
      <td><input name="email1" type="text" size="40" value="" />
       <input name="send" type="submit" value="  Send  " />
	   <input type="hidden" name="org_pk" id="org_pk"
  value="<?php echo $_POST['org_pk']; ?>" />
      </td>

The website is one that lists mental health resources. If you go to the page given you will see the form by clicking the "Send info as Email" buttons in the right-hand cells.
Many thanks for looking at this for me.
Steve
 
A: Where does your code get $comment from the form submitted data?


B: have you tested to ensure that $comment actually has a value to start with?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Thanks for replying, Chris.
Let's face it, I'm a bit out of my depth here!
I have tested, as you suggest, and sure enough $comment has no value.
It originally got its value from the textarea (my third piece of code above), or so I thought, although I wrote all this some years ago and have forgotten how it was supposed to work now.
What I am attempting is to allow a user to add a message ($comment) which will be included in an email with the other data, which is already presented on the same page, and which comes from my MYSQL dbase.
Clearly the system is not creating $comment. Can you point me in the right direction?
Many thanks for your trouble.
Steve
 
Where is the code that looks something like;

PHP:
<?php
$comment = $_POST['comment'};

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Form values don;t automatically get set to PHP variables. Depending on what method your form is using the value will be in either $_GET['comment'] or $_POST['comment']

Fropm there you can set $comment.

$comment=$_POST['comment'];



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
@OP

long ago all POST variables (and query variables) were automatically populated in php. so $comment would have been available and would have contained the value of the comment textarea. But this was changed ages ago as it is a big security headache. This may be why this kind of code used to work for you, but no longer does.
 
Thanks for all the help.
Problem now solved, and the reason for it has even been understood!
Best wishes
Steve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top