2

I am trying to send an email address from my index.php to form.php file. In form.php I get the email address correctly or prints correctly. But when i am trying to sending an email to that particular email address using php mail() function. It's not working. Can anyone suggest me how to fix this ?

index.php

 <form method="POST" action="Form.php">
 <input type="email"  name="email" placeholder="Email" >
 <input type="submit" name="submit" id="submit-form" class="hidden" style="display:none">
 </form>

Form.php

<p>To :'.$_POST["email"].'</p> // showing email address

<?php
 if (isset($_POST['submit'])) {
    $to = $_POST["email"];     // does not sending email
    $subject = 'my subject';
    $headers[] = 'MIME-Version: 1.0';
    $headers[] = 'Content-type: text/html; charset=iso-8859-1';
    $headers[] = 'From: my@email.com';
    mail($to, $subject, $hippo , implode("\r\n", $headers));
}
?>  
<div id="submitBtn">
<label for="submit-form" class="submitBtn">Submit</label>
</div>
Ami Hasan
  • 125
  • 14

2 Answers2

1

You don't have a submit button in your form and you ask if submit was in form the correct way is

<form method="POST" action="Form.php">
  <input type="email"  name="email" placeholder="Email" >
  <input type="submit" value="submit"/>
</form>

And now the code of Form.php will work

Castro Alhdo
  • 293
  • 3
  • 8
0

Check your headers and mail() function, see if it is actually redirecting you to the form page or not,

try the code below :

index

<form method="POST" action="Form.php">
<input type="email"  name="email" placeholder="Email">
<input type="submit" name="submit" id="submit-form">
</form>

Form

$to      = $_POST['email'];
$subject = "My Subject" ;
$message = "Got the mail";
$header = "From: my@email.com\r\n"; 
$header.= "MIME-Version: 1.0\r\n"; 
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
$header.= "X-Priority: 1\r\n";

mail($to, $subject, $message, $header);
Arsalan Mithani
  • 490
  • 3
  • 11