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 = '[email protected]';
$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 = "[email protected]";
$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
https://forums.phpfreaks.com/topic/238682-php-contact-form/
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: [email protected], 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
https://forums.phpfreaks.com/topic/238682-php-contact-form/#findComment-1226533
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
https://forums.phpfreaks.com/topic/238682-php-contact-form/#findComment-1226541
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
https://forums.phpfreaks.com/topic/238682-php-contact-form/#findComment-1226543
Share on other sites

unless someone else can spot an error, i cant. I would assume that it ws because your previous server host did not set up the mail server for you...I found a site that describes what to look for and how to set up you php.ini file to reflect your smtp mail server settings...http://php.devquickref.com/php-smtp-mail-auth-aaa-setup-php-ini.html

Link to comment
https://forums.phpfreaks.com/topic/238682-php-contact-form/#findComment-1226558
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
https://forums.phpfreaks.com/topic/238682-php-contact-form/#findComment-1226596
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.