Skip to content

Instantly share code, notes, and snippets.

@rawars
Last active June 20, 2020 19:25
Show Gist options
  • Save rawars/47b42808e7392ed652287460d5719ffd to your computer and use it in GitHub Desktop.
Save rawars/47b42808e7392ed652287460d5719ffd to your computer and use it in GitHub Desktop.
<?php
if(isset($_POST["to"]) && isset($_POST["subject"]) && isset($_POST["message"]) && isset($_POST["header"])){
   
    $from = "[email protected]";
        
    $to = $_POST["to"];
        
    $subject = $_POST["subject"];
        
    $message =$_POST["message"];
        
    $headers = "From:" . $_POST["header"] . "<" . $from . ">" . "\r\n";

    if(mail($to,$subject,$message, $headers)){
        print json_encode([
            "success" => true,
            "data" => 'E-mail sent'
        ]);
    }else{
        print json_encode([
            "success" => false,
            "data" => 'E-mail not sent'
        ]);
    }
     
}else{
    print json_encode([
        "success" => false,
        "data" => 'Incomplete data'
    ]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment