Danial Danial - 1 year ago 82
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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download