0

Just want to start of by saying im a total beginner at PHP. I have created a php mail form on one website and the same form on a different folder in the same shared account (shared GoDaddy cPanel).

The form looks like:

<form id="1-form" name="1-form" method="post" action="mail-form.php">

<div class="form-group">
<label for="1-name"> Name </label>
<input type="text"  id="1-name" name="1-name" class="form-control name-field" required="required">
</div>

<div class="form-group">
<label for="1-email"> Email </label>
<input type="email" id="1-email" name="1-email" class="form-control name-field" required="required">
</div>

<div class="form-group">
<button id="quote-submit" type="submit" class="btn btn-primary">Send</button>
</div>

</form>

And the mail-form.php file looks like:

<?

$name=$_POST['1-name'];
$Email=$_POST['1-email'];


    $body .= "Name: " . $name . "\n"; 
    $body .= "Email: " . $Email . "\n"; 


   
    mail("example@email.com","New email",$body); 

  
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script>alert("Your message has been sent successfully. We will contact you shortly.");</script>
<meta HTTP-EQUIV="REFRESH" content="0; url=../index.php"> 

</head>

I duplicated these files in two different folders and one of them works fine and the other for some reason shows empty values. In my email it would show up like:

name: email:

I cant pinpoint whats wrong. All help is appreciated. - Thanks

  • 1
    try using ` – Rotimi Oct 17 '17 at 19:11
  • While the advice provided by @Akintunde is correct in general, it doesn't explain why your code doesn't work. If the [short open tags](http://php.net/manual/en/language.basic-syntax.phptags.php) are not enabled the PHP code surrounded by them is not interpreted at all (and consequently, the for that sends empty emails would not send anything). – axiac Oct 17 '17 at 19:16
  • 1
    Verify that there's actually data in your `$_POST` variables before you send the form, or else you're going to get a lot of empty emails from bots, crawlers, and just random traffic. – aynber Oct 17 '17 at 19:20
  • It's also better if you initialize `$body` before you try to append to it. You'll get warnings, otherwise. – aynber Oct 17 '17 at 19:21
  • 1
    Enable `display_errors`, set `error_reporting` to `E_ALL` and remove your meta refresh to see any notices, there should be anything. – clemens321 Oct 17 '17 at 19:23
  • 1
    You can't have form names that start with numbers. Change them. – John Conde Oct 17 '17 at 19:25
  • @JohnConde I haven't heard that one before. Is there a source for that? – aynber Oct 17 '17 at 19:35
  • 1
    Never mind, I found it at https://www.w3.org/TR/html401/types.html#type-cdata – aynber Oct 17 '17 at 19:38

0 Answers0