html - PHP mail() function sends empty variables -
for reason name, email , message appear empty when receive email.
html
<form method="post" action="send.php" class="form-horizontal"> <fieldset> <!-- text input--> <div class="form-group"> <label class="col-md-4 control-label" for="name">name</label> <div class="col-md-4"> <input id="name" name="name" type="text" class="form-control input-md" required=""> </div> </div> <!-- text input--> <div class="form-group"> <label class="col-md-4 control-label" for="email">email</label> <div class="col-md-4"> <input id="email" name="email" type="email" class="form-control input-md" required=""> </div> </div> <!-- textarea --> <div class="form-group"> <label class="col-md-4 control-label" for="message">message</label> <div class="col-md-4"> <textarea class="form-control" id="message" name="message"></textarea> </div> </div> <!-- button --> <div class="form-group"> <label class="col-md-4 control-label" for="submit"></label> <div class="col-md-4"> <button id="submit" name="submit" type="submit" value="submit" class="btn btn-outline-inverse btn-lg">submit</button> </div> </div> </fieldset> </form> php code simplified example
<?php $emailto = "example@example.com"; $subject = "example subject"; $name = trim(stripslashes($_post['name'])); $email = trim(stripslashes($_post['email'])); $message = trim(stripslashes($_post['message'])); $headers = "from: example@example.com\r\n"; $headers .= "reply-to: example@example.com\r\n"; $headers .= "content-type: text/html; charset=iso-8859-1" . "\r\n"; $body = "<p>you have received new message:</p> <p><strong>ime: </strong> {$name} </p> <p><strong>email address: </strong> {$email} </p> <p><strong>poruka: </strong> {$message} </p>"; $success = mail($emailto, $subject, $body, $headers); if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;url=thanks.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;url=error.html\">"; } ?> for reason variables $name, $email , $message appear empty when receive email contact form/mail function. rest shown correctly.
you need close " in $body variable.
$body = "<p>you have received new message:</p> <p><strong>ime: </strong> {$name} </p> <p><strong>email address: </strong> {$email} </p> <p><strong>poruka: </strong> {$message} </p>"; php html
No comments:
Post a Comment