Jump to content

PHP Contact Form


bscyb

Recommended Posts

hello i have a contact form on my site and via PHP i send the message to my e-mail but i think something is wrong with PHP script cause i dont get any e-mail when i write a message

 

heres the html contact form code

 

html

<form name="cform" action="form-to-email.php" method="post" onsubmit="return validate()">
<h4>Contact Form</h4>
   <p>Στείλτε μας τις απορίες και τα σχόλια σας
   <br />
   </p>

   <ol>
        
        <li>
           <label for="name"> <font color="maroon">*</font>Name:</label>
           <input type="text" name="name" id="name" tabindex="1" />
        </li>
        
        <li>
           <label for="email"><font color="maroon">*</font>Email:</label>
           <input type="text" name="email" id="email" tabindex="2" />
        </li>
        
        
        
        <li>
           <label for="message"><font color="maroon">*</font>Message:</label>
           <textarea name="message" id="message" tabindex="3"  rows="3" ></textarea>
        </li>
        
        <li id="send">
           <button type="submit" >Send</button>
        </li>
   
    </ol>

</form>   

 

 

and heres the PHP script

<?php

$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];



$email_from = 'nick_171717@hotmail.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
    "Here is the message:\n $message".
    
$to = "nick_171717@hotmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";

mail($to,$email_subject,$email_body,$headers);
header('Location: index.php');

?> 

Link to comment
Share on other sites

You shouldn't spoof your visitor's emails, you should put the email in the reply-to, but you should create an email from YOUR domain name, like: alerts@yourDomain.com, to send emails, because most times when you send an email from your webserver with a different domain name, it goes straight to junkmail, sometimes not accepted at all..

Link to comment
Share on other sites

in order to send mail using the mail() function. You will need to declare a valid SMTP (Simple Mail Transfer Protocol) in you php.ini file. When the mail() function attempts to send mail, it opens an SMTP socket in order to send the mail. I assume that you are using localhost to test your site? I recommend that you put your site on a recommended server that already has SMTP etc configured

Link to comment
Share on other sites

in order to send mail using the mail() function. You will need to declare a valid SMTP (Simple Mail Transfer Protocol) in you php.ini file. When the mail() function attempts to send mail, it opens an SMTP socket in order to send the mail. I assume that you are using localhost to test your site? I recommend that you put your site on a recommended server that already has SMTP etc configured

ok i will put my site on a recommended server that has smtp

but the PHP script has something wrong because i test it before some weeks when i had my site uploaded on 000webhost but it was not sending any e-mail

Link to comment
Share on other sites

did you have error reporting on/check the error log for any errors that were triggered when the script was run? offhand, i dont see any errors that would cause your script to not send an email...my first guess would be a server issue

Link to comment
Share on other sites

Javascript is NOT validation. All validation of data must be done server-side. A user can disable javascript in their browser, and send whatever values they want to your script without restriction. JS is really nothing more than a way to improve (or in some cases, destroy) convenience and usability.

Link to comment
Share on other sites

we can see by your onsubmit event that you are infact using JS to validate your form. While there are ways to work around a user having JS disabled, like using <noscript> tags, Pikachu is right in saying that it should never be used as validation.

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.