-2

$name = htmlentities(filter_var($_POST['uname'], FILTER_SANITIZE_STRING));
    $email = htmlentities(filter_var($_POST['email'],FILTER_VALIDATE_EMAIL, FILTER_SANITIZE_EMAIL));
    $date = htmlentities(filter_var($_POST['date'],FILTER_SANITIZE_EMAIL));
    $message = htmlentities(filter_var($_POST['message'], FILTER_SANITIZE_STRING));
    $phone_number = htmlentities(filter_var($_POST['phone'],FILTER_SANITIZE_NUMBER_INT));

            $response= "<span class='text-danger'><strong>Server is busy try later</strong></span>"; $success = 0;

        $to = "<myemail>";
        $subject = "Reservation";



        $headers = "From: $email\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

        $messageHTML = '<html><body>';
        $messageHTML .= '<h1>'.'<a href=mailto:'.$email.'>'.'Click Here To RESPOND!</a></h1>';
        $messageHTML .= '<h4>'.'Sender Name : '.$name.'</h4>';
        $messageHTML .= '<h4>'.'Sender Email : '.$email.'</h4>';
        $messageHTML .= '<h4>'.'Date : '.$date.'</h4>';
        $messageHTML .= '<h4>'.'Sender Phone Number : '.$phone_number.'</h4>';
        $messageHTML .= '<h4>'.'Message :'.'</h4>';
        $messageHTML .= '<p>'.$message.'</p>';
        $messageHTML .= '</body></html>';
        $body = $messageHTML;


        if(mail($to, $subject,$body,$headers)){         
            $success = 1;
            $response= "<span class='text-success'><strong><h1>Your Table is unconfirmed.</h1> We have received your message and we will email you confirmation within a day or two </strong></span>";
        }else{      
            $success = 0;
            $response= "<span class='text-danger'><strong>Server is busy try emailing us here: enquiries@whodcornwall.co.uk</strong></span>";
        } else{ 
          $success = 0;  
          $response= "<br><span class='text-danger><strong>Please fill all required fields.</strong></span>";
        } 
        echo json_encode(array('successs'=>$success,response'=>$response));

Trying to make a from header so when it sends to my email it says 'from $email' but it won't let me change it to that as the form just stops working. It currently works with the hostname email addresses but is there a way I can make it work with anything people write in the email address field?

Matthias Neubert
  • 275
  • 1
  • 5
  • 24
  • 1
    _"the form just stops working"_ You will need to explain what this means. – Alex Howansky Mar 22 '18 at 15:09
  • You should separate the two filter function in the 3rd line. – Lithilion Mar 22 '18 at 15:10
  • Use a library like [phpmailer](https://github.com/PHPMailer/PHPMailer) or [swiftmailer](https://github.com/swiftmailer/swiftmailer), it really simplifies things for you. –  Mar 22 '18 at 15:11

1 Answers1

-1
$to = 'mail@example.com';
$subject = 'Website Change ';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan@example.com\r\n"; 
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/htmlcharset=UTF-8\r\n";
$message = '<p><strong>This is strong text</strong> while this is not.</p>';
mail($to, $subject, $message, $headers);

Hope this will help you ..