2

My php script to send mail is as follows :

<?php
    if (isset($_POST['submit'])) {
        $to='info@animalswecare.com';
        $fname=stripslashes($_POST['fname']);
        $email=$_POST['email'];
        if (get_magic_quotes_gpc())
            $email = stripslashes($email);
        //$email=trim($email, '/');
        $msg=$_POST['msg'];
        $msg=stripslashes($msg);
        $message="Name: $fname\n" ."Message: $msg\n";
        mail($to,$subject,$message,'From:'.$email)  ;
    }
   ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact us">
  <label>Name:</label>
  &nbsp;&nbsp;&nbsp;
  <input type="text" name="fname" value=<?php if(!empty($fname)) echo $fname; ?>  /><br />
  <label>Email:</label>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="email" value=<?php if (!empty($email)) echo $email; ?> /><br />
  <label>Message:</label>
  <textarea name="msg" rows="5"><?php if (!empty($msg)) echo $msg; ?></textarea>      <br />
  <input type="submit" name="submit" value="Post" />
</form> 

But when the form appears, there is a / added in every field. I have tried using trim, rtim, get magic quotes and stripslashes but nothing is working.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
ashish
  • 49
  • 1
  • 7

4 Answers4

3

It because your value='s are not being ended.

Try this: <input type="text" name="fname" value="<?php if(!empty($fname)) echo $fname; ?>" /> and apply the same learning's to all of the inputs.

Also I re-formatted your code and added label in the CSS..so you don't have use those ugly line-spaces.

<?php

if (isset($_POST['submit'])) {
    $to = 'info@animalswecare.com';
    $fname = stripslashes($_POST['fname']);
    $email = $_POST['email'];

    if (get_magic_quotes_gpc()) {
        $email = stripslashes($email);
    }

    // $email = trim($email, '/');
    $msg = $_POST['msg'];
    $msg = stripslashes($msg);    
    $message = "Name: $fname\n" ."Message: $msg\n";
    mail($to, $subject, $message, 'From:' . $email);
}

?>

<style>
    label {width: 120px;}
</style>

<form action="" method="post">

    <label>Name:</label>
    <input type="text" name="fname" value="<?php if(!empty($fname)) echo $fname; ?>"  /><br />
    <label>Email:</label>
    <input type="text" name="email" value="<?php if (!empty($email)) echo $email; ?>" /><br />
    <label>Message:</label>
    <textarea name="msg" rows="5"><?php if (!empty($msg)) echo $msg; ?></textarea><br />
    <input type="submit" name="submit" value="Post" />

</form> 
Kalle H. Väravas
  • 3,579
  • 4
  • 30
  • 47
1

try adding " " around the value attribute

ie

<input type="text" name="email" value="<?php if (!empty($email)) echo $email; ?>" />
mreq
  • 6,414
  • 4
  • 37
  • 57
0

This will teach you to follow standards and always enclose tag parameter values in quotes

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
0

First of all, don't use stripslashes(). Simply disable magic_quotes_gpc completely, using the php.ini file or .htaccess. If you can't, view the accepted answer to this question: How to turn off magic quotes on shared hosting?

About your error...

value=<?php if (!empty($email)) echo $email; ?> />

If you look, you didn't put the quotes around the attribute "value".

value="<?php if (!empty($email)) echo $email; ?>" />

will fix it

Community
  • 1
  • 1
ItalyPaleAle
  • 7,185
  • 6
  • 42
  • 69