What should be the PHP code so that I can receive the email address of the person who submits his email address ← (PHP, HTML)
I have already linked my newsletter subscription box given in contact.html with newsletter.php
But when I am trying to send the email address in the subscription box to my mailbox, I am not receiving the email address given in the box rather I am receiving a blank mail.enter image description here
contact.html Code
<div class="form-element">
<form action="newsletter.php" method="post">
<input name="email" type="email" placeholder="Email" required><span><a href="newsletter.php"><i type="submit" class="fas fa-chevron-right"></i></a></span>
</form>
</div>
newsletter.php Code
<?php
$visitor_email = $_POST['email'];
$email_from = 'info@unboxproduct.in';
$email_subject = "Newsletter Subscribtion";
$email_body = "Subscriber Email: $visitor_email.\n";
$to = "info@unboxproduct.in";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: contact.html");
?>
Answer
Solution:
Form Code:-
<div class="form-element">
<form action="newsletter.php" method="post">
<input name="email" type="email" placeholder="Email" required>
<i type="submit" class="fas fa-chevron-right"><input type="submit" name="submit" value="Email Now"></i>
</form>
</div>
Mail Code:-
<?php
$visitor_email = $_POST['email'];
$email_from = 'info@unboxproduct.in';
$email_subject = "Newsletter Subscribtion";
$email_body = "Subscriber Email: $visitor_email.\n";
$to = "info@unboxproduct.in";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: contact.html");
?>