Forum Moderators: coopster

Message Too Old, No Replies

form frustration

         

Gilead

8:11 pm on Nov 11, 2011 (gmt 0)

10+ Year Member



I'm adding a new feature to the add-user script.
Once the new user is entered, the admin has the option to send the user's details at that point or wait til later.

I tried to make it a function inside the script, but couldn't make the call from an anchor tag, so I decided to make it a separate page. I used a form with one submit button and hidden tags to send the data via GET.

The mail was not sent and my error checking showed that the variables are not coming through. What can I do?

From addnew.php
...?> //in the HTML section
<form action="email_user.php" method="get"><input type="submit" value="SEND USER EMAIL"/>
<input type=hidden value="$login" />
<input type=hidden value="$password" />
<input type=hidden value="$email" />
</form><br />

mail_user.php
$to=$_GET[email];
$login=$_GET[login];
$password=$_GET[password];

echo $to;
echo $login;
echo $password;

$subject = "Login Information";
$headers = "From: No Reply customerservice@email.com\n";
$body = "Here are your login details:\n";
$body .="Username:". $login. "\n";
$body .="Password:". $password. "\n";
$body .="Make sure you login and change your password immediately.";

if(mail($to,$subject,$body,$headers))
{
echo "Login Details Sent to";
echo $to;
}
else
{
echo "Message Not Sent";
}

Thanks!

eelixduppy

9:28 pm on Nov 11, 2011 (gmt 0)



Are you getting any errors? Try adding this to your script:

error_reporting(E_ALL);

penders

10:38 pm on Nov 11, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<input type=hidden value="$email" />


All attribute values should be quoted and your form inputs need a name attribute. And how are you outputting your PHP variables? I think this should be more like this...(?)
<input type="hidden" name="email" value="<?php echo $email ?>" />


mail_user.php
$to=$_GET[email];


Again, you need to quote the array elements, like so...
$to = $_GET['email'];


As eelixduppy suggests, error_reporting(E_ALL) is your friend here... this would alert you to these errors.

(The same with your other form inputs.)

$headers = "From: No Reply customerservice@email.com\n";


Depending on your server, email headers are usually separated by "\r\n", not just "\n" (ok in the email body). And if you are including the persons name ('No Reply' in this case), you probably need to surround the email in angled brackets...
$headers = "From: No Reply <customerservice@email.com>\r\n";


$body .="Password:". $password. "\n";


Aside: Sending the password unencrypted in the email is usually a bit of a security no no. (As well as in the form, unless maybe you are using SSL?).

Gilead

4:06 pm on Nov 14, 2011 (gmt 0)

10+ Year Member



WORKS! Thank you! I'll stop making stupid mistakes eventually. :-)

In this particular case, it is a generated password to be changed by the member. When I work on the user-side, I'll encrypt it before it's inserted.