Jump to content

PHP contact from


NicoleStrain

Recommended Posts

Hello I have a PHP contact from for a website im making. The form is sending the email ok however the content in the email is wrong as its sending the HTML script. Im only using Notepad ++ to make the website and that dosent have a error checker so i used a website called http://phpcodechecker.com/ but that said there is no errors in my code which there must be. Could someone have a check for me please ?

This is my first time using PHP so it probably a silly mistake. Thanks in advanced !

 

<?php
if(isset($_POST['email'])) {
    
    // CHANGE THE TWO LINES BELOW
    $email_to = "nicoles@mailmarkscot.com";
    
    $email_subject = "Website Bookin";
    
    
    function died($error) {
        // your error code can go here
        echo "We're sorry, but there's errors found with the form you submitted.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
    
    
    
$name = $_POST['name']; 
$email_address = $_POST['email']; 
$tell = $_POST['tell'];
$date = $_POST['date'];
$service = $_POST['service'];
$eMessage = $_POST['message']; 
    
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  
    


$message = '
<html>
<head>
<p> You have received a new booking request. <br/>


Name: $name <br/>


Email: $email_address <br/>


Tell: $tell <br/>


Date: $date <br/>


Service: $tell <br/>


Message: $eMessage </p> 
</body>
</html> ';


   
    
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject,$message,$headers);  
?>


<!-- place your own success html below -->


Thank you for contacting us. We will be in touch with you very soon.


<?php
}
die();
?>

 

post-203462-0-96143800-1486387869_thumb.png

Link to comment
Share on other sites

Why not try to send a plain text email until you learn to do the right research to send an html-based one?

 

Also - add error checking at the top of your script to point out php problems as they occur.

 

And - don't bury a function into the middle of your code. It interrupts the flow of reading the code for no reason.

 

Question - what is died() even used for?

 

Question 2 - what is $email_exp for?

 

Question 3 - if you are going to use html, where is the <body> tag?

Link to comment
Share on other sites

Hello thanks for replying,

 

I hadnt realized that i was missing the body tag, ive been playing about with that much ive deleted it at one point by accident.

I got the code from a demo file offline which i altered to my contact from so being completely honest im not sure what died() or $email_exp is used for.

 

Ill take your advice but and stick to a plan text email until ive learned more, would rather have an email that works instead of one that looks good.

Link to comment
Share on other sites

Well said! I appreciate your honest response to the things I wrote about. Be happy to review and advise on your next post - especially if you do the things I suggested.

 

See my signature for the error checking code you need to add. And - you should actually try to learn from doing your own research instead of just copying other's (feeble) attempts. You will have a much faster education.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.