0

I have wrote a simple php mail function which is on server which is showing error that mail not send , I have also checked if mail function worked or not and it showed that mail function is working but my this script is not working which is below

    <?php
    /*
     * Enable error reporting
     */
    ini_set( 'display_errors', 1 );
    error_reporting( E_ALL );

    /*
     * Setup email addresses and change it to your own
     */
     if(isset($_POST['send'])){
         var_dump($_POST);
     $from = "no-reply@skynetinfosolution.com";
    $to = $_POST['to'];
    $subject = $_POST['subject'];
    $message = $_POST['body'];
    $headers = "From:" . $from;

    /*
     * Test php mail function to see if it returns "true" or "false"
     * Remember that if mail returns true does not guarantee
     * that you will also receive the email
     */
    if(mail($to,$subject,$message, $headers))
    {
        echo "Test email send.";
        $headers .="MIME-Version: 1.0" . "\r\n";
         $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

    } 
    else 
    {
        echo "Failed to send.";
         //ror_get_last();


    }

     }
?>
        <form action="mail2.php" method="post">
    To<input type="email" name="to" placeholder="Enter email"><br/>
    Subject<input type="type" name="subject" placeholder="Subeject"><br/>
    Body<input type="text" name="body" placeholder="Body Message">
    <input type="submit" name="send" value="Send">
    </form>
    </body>
    </html>
Jay Arya
  • 53
  • 11
  • It may not be the cause of your problem but you do have 2 form start tags with the same action and no form end tag. Try removing the second one and also put in a var_dump($_POST); in your processing script to make sure you are receiving the POST variables. – Fergal Andrews Jun 20 '18 at 08:11
  • 1
    it seems [you can use `error_get_last()`](http://php.net/manual/en/function.mail.php#121163) to get an error message – Karsten Koop Jun 20 '18 at 08:12
  • 1
    you change the value of `$headers` after it was passed to `mail()`; the new content is then never used – Karsten Koop Jun 20 '18 at 08:13
  • i have modified it but nothing working – Jay Arya Jun 20 '18 at 08:31
  • Bit of a left field possibly problem, but it could be to do with the hosting. Some hosting providers won't let you use the default mail from a server without going through an external SMTP server. Have you tried connecting to an external SMTP server or relay? – gabe3886 Jun 20 '18 at 08:35
  • Does your server actually have a SMTP server running? – Gnudiff Jun 20 '18 at 08:52
  • actually it is a linux hosting , and I dont know how to chekc if smtp support or not – Jay Arya Jun 20 '18 at 08:56
  • to check if server has smtp https://stackoverflow.com/a/11988455/8813684 – Naresh Kumar Jun 20 '18 at 09:19

0 Answers0