0

i got 500 internal server error for mail ids which doesn't exist like test@test.com. how can i fix it. i used try catch but error still there. but for real mail ids mail send and redirected to thank you page. please help.

if(isset($_POST["submit_msg"]))
{
    try{
        $contact_name=mysqli_real_escape_string($mysqli,$_POST["contact-name"]);
        $contact_email=$_POST["contact-email"];
        $ph=$_POST["contact-subject"];
        $msg=mysqli_real_escape_string($mysqli,$_POST["contact-message"]);

        $insert_query="insert into contact values('$contact_name','$contact_email','$ph','$msg','')";
        $mysqli->query($insert_query);

        $date=date("d/M/y");


        $to = "chippy@gmail.com";

        $subject = "ril - Enquiry from Contact ".$date;
        $headers .= 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= "From: abc@gmail.com" ;

        $to1 = $contact_email;
        $subject1 = "Raindrops Nursery - Enquiry from Contact ".$date;
        $headers1 .= 'MIME-Version: 1.0' . "\r\n";
        $headers1 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers1 .= "From: abc@gmail.com" ;

        $body1="<div class='msg'> <p>Dear ".$contact_name .",<br /><br />Thank you for your enquiry. It has been forwarded to the relevant department and<br /> will be dealt with as soon as possible.<br /><br />"."</p>"."</div>";

        $body="<table border='1'>"."<tr><td>Name</td><td>".$contact_name."</td></tr>"."<tr><td>Email</td><td>".$contact_email."</td></tr>"."<tr><td>Phone</td><td>".$ph."</td></tr>"."<tr><td>Message</td><td>".$msg."</td></tr></table>";

        mail($to, $subject, $body, $headers);
        mail($to1, $subject1, $body1, $headers1);

    } catch (Exception $ex) {    
        file_put_contents("log.txt","error found!".$ex.PHP_EOL,FILE_APPEND);
    }
    finally {

        echo "<script>window.location='thank-you.php'</script>";
    }
}
Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49
chippy
  • 74
  • 10
  • 2
    Have you tried PHP error debugging ? – Varun Nov 23 '17 at 05:31
  • provide the actual error message. you can find it in your error log. – Gordon Nov 23 '17 at 06:30
  • no.nothing written in error log. it never enters in catch block – chippy Nov 23 '17 at 06:45
  • 1
    simply changing the email address is unlikely to cause a 500. Even the "mail" function might not fail in that situation, since it's the remote mailserver at the addressed domain which determines whether the address exists or not - more likely you'd just get a bounceback. Something else is the problem. Turn on PHP error reporting and check what's going on, and/or add some debugging output to your code so you can see where it fails. – ADyson Nov 23 '17 at 09:01

0 Answers0