PDA

View Full Version : PHP email script variable issue


gavimobile
04-25-2008, 12:29 AM
hey folks,
i have a list which i did from the dwc tutorial.
list adds/deleted users, and displays the info below the submit form.
one of the fields in the list is email, which is a link that says "contact user".
so we click on the link and we are taken to the contact form so we can contact the user we clicked on. From the list to the individual contact form works fine. I know cause i did this on the top.

echo "<h1>".$row['adm_email']."</h1>";and it displays the user that i clicked on so im doing something right :-)

so my email script (the actions location for the form) has something wrong with it.
when i fill out the form i get the error

Warning: mail() [function.mail]: SMTP server response: 503 Must have sender and recipient first.
i correct the problem by specifing an email address for $to = "email@here.com"I want it to be $to = $email_variable_here

But when i do that, i get the error.

email form -

<?php

require_once('../includes/config.php');

$query = sprintf("SELECT * FROM adm WHERE adm_id=$getemail");
$results = @mysql_query($query);
$row = @mysql_fetch_array($results);

?>
<html>
<body>
<?
echo "<h1>".$row['adm_email']."</h1>";

if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
mail( $adm_email, "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='../includes/classes/contact_user_script.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
</body>
</html>

email script (the action) -

<?php

require_once('../config.php');


$query = sprintf("SELECT * FROM adm WHERE adm_id=$getemail");
$results = @mysql_query($query);
$row = @mysql_fetch_array($results);

echo "<h1>".$row['adm_email']."</h1>";

$to = $adm_email;
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = $email;
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.<br /><a href=email@here.com/'>Go Back</a>";

?>
here are my variables to which i keep in the config.php file

$adm_usr = $_POST['adm_usr'];
$adm_pass = $_POST['adm_pass'];
$adm_email = $_POST['adm_email'];
$submit = $_POST['submit'];
$del = $_GET['del'];
$getemail = $_GET['getemail'];

$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
TIA
GAVIMOBILE

lux
04-25-2008, 10:59 AM
change

$to = $adm_email;

to

$to = $row['adm_email'];


___________________

if you echo $adm_email you will find there is no value. why? because your not posting the variable in your form

you can try using a hidden field in your form to send the adm_email like this:


<input type="hidden" name="adm_email" value="<?php $row['adm_email']; ?>" />

gavimobile
04-25-2008, 05:50 PM
lex thanks for the reply, unfortunetly it didnt solve the problem. Im still in the same position as before.

email script -

<?php

require_once('../config.php');

$query = sprintf("SELECT * FROM adm WHERE adm_id=$getemail");
$results = @mysql_query($query);
$row = @mysql_fetch_array($results);

$to = $row['adm_email'];
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = $email;
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.<br /><a href='email@here.com'>Go Back</a>";
echo "<h1>".$row['adm_email']."</h1>";

?>
contact form -

<?php

require_once("../includes/config.php");

$query = sprintf("SELECT * FROM adm WHERE adm_id=$getemail");
$results = @mysql_query($query);
$row = @mysql_fetch_array($results);

?>
<html>
<body>
<?
echo "<h1>".$row["adm_email"]."</h1>";

if (isset($_REQUEST["email"]))
//if "email" is filled out, send email
{
//send email
mail( $adm_email, "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
?>
<form method="post" action="../includes/classes/contact_user_script.php">
Email: <input name="email" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
<input type="hidden" name="adm_email" value="<?php $row["adm_email"]; ?>" />
</form>

<?
}
?>

</body>
</html>
anyone else?

lux
04-25-2008, 06:47 PM
try


mail( $row["adm_email"], "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}

gavimobile
04-25-2008, 07:49 PM
try


mail( $row["adm_email"], "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}


still no :-(.... i took out the bracket, i didnt know why u added a closing bracket if i didnt even have an opening bracket

thanks for your quick reply :-) can you suggest something else?
tia


<?php

require_once('../config.php');

$query = sprintf("SELECT * FROM adm WHERE adm_id=$getemail");
$results = @mysql_query($query);
$row = @mysql_fetch_array($results);

$to = $row['adm_email'];
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = $email;
$headers = "From: $from";

mail( $row["adm_email"], "Subject: $subject", $message, "From: $email" );
echo "Mail Sent.<br /><a href='email@here.com'>Go Back</a>";
echo "<h1>".$row['adm_email']."</h1>";

?>

lux
04-25-2008, 08:32 PM
$to = $row['adm_email'];
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = $email;
$headers = "From: $from";

mail( $to, "Subject: $subject", $message, "From: $email" );
echo "Mail Sent.<br /><a href='http://www.motekpc.com/adm/'>Go Back</a>";
echo "<h1>".$row['adm_email']."</h1>";

gavimobile
04-25-2008, 08:44 PM
$to = $row['adm_email'];
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = $email;
$headers = "From: $from";

mail( $to, "Subject: $subject", $message, "From: $email" );
echo "Mail Sent.<br /><a href='http://www.motekpc.com/adm/'>Go Back</a>";
echo "<h1>".$row['adm_email']."</h1>";


same thing :-(


$to = $row['adm_email'];
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = $email;
$headers = "From: $from";

mail( $to, "Subject: $subject", $message, "From: $email" );
echo "Mail Sent.<br /><a href='http://www.domain.com/adm/'>Go Back</a>";
echo "<h1>".$row['adm_email']."</h1>";

lux
04-25-2008, 08:50 PM
if you echo $to outside the mail() function does it contain a value.

sorry for not giving you a correct answer, i'm rubbish tonight

trying my hand at apaches mod_rewrite at the moment, which isn't not fun! haha

gavimobile
04-25-2008, 09:06 PM
if you echo $to outside the mail() function does it contain a value.

sorry for not giving you a correct answer, i'm rubbish tonight

trying my hand at apaches mod_rewrite at the moment, which isn't not fun! haha

we all have our bad days. thanks for trying

gavimobile

lux
04-25-2008, 09:09 PM
so when you echo $to what is printed to the screen?

gavimobile
04-25-2008, 09:20 PM
echoing $to
came out with nothing!

thanks

lux
04-25-2008, 09:24 PM
give me a shout if you need any more help.

good luck

gavimobile
04-25-2008, 09:26 PM
give me a shout if you need any more help.

good luck

i pmed dj i hope he will save the day "once again"

also can one of the mods edit edit the post and delete my location names.. example chage mydomain.com to domain.com
also if it says /location/of/file.php change to /folder/file/example.php
my mistake for not reviewing it before post.. now im kinda stuck

lux
04-25-2008, 09:28 PM
well isn't the problem that your not passing a value to the variable $to.

so fix that and you'll have your answer.

davidj
04-26-2008, 10:32 AM
lux is giving you his valued time

please follow his instruction and you will find your problem

gavimobile
02-10-2009, 03:15 PM
could one of the admins remove me domain from the post.. its been posted a few times acidently in this post. im trying to keep harvesters away.

search any instance with the word "ekpc.com" to find the domain im talking about in this post so you can remove it.

i appreciate it

thanks
guys