Danial Danial - 12 days ago 7
PHP Question

mail funtion to not send blank emails and to send not blank emails in php

"If $email is empty then don't send email. done."
"If $email is not empty then send email. problem."


<?php if(isset($_POST["Submit"]))
{
$email = $_POST["emailaddress"]; }$to = "someone@example.com"; $subject = ""; $message = ""; $headers = "From: " .$email; if (isset($_POST["submit"]) && (!empty($email)))
{
$success = mail($to, $subject, $message, $headers); 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
Replace this edited code 

$from = "Danial@example.com";
$to = "someone@example.com";
$subject = "Hi,";
$message = "This mail is testing mail by $from";
if (isset($_POST["submit"]) && (!empty($email)))
{
    $success = mail($to, $subject, $message);
}