Danial Danial - 9 months ago 55
PHP Question

how to restrict mail funtion to send blank emails in php

"If $email is empty then don't send email. how to do this."
"Every time I submit empty email, it sent blank emails to my inbox. how to restrict this."

<?php $email = $_POST["email"]; $to = "someone@example.com"; $subject = ""; $success = mail($to, $subject, $message); if ($success){
echo "<script>alert('Subscription Done! Please Stay tuned.')</script>"; }else{
echo "<script>alert('Email for Newsletter subscription was not successful.')</script>"; die();

Answer Source
Replace your 8th line if condition by following

if (isset($_POST["submit"]) && (!empty($email)))
    $success = mail($to, $subject, $message);