0

This is the code for my form

 <form name="contactform" method="post" action="sentfrommail.php">
  <h1 style="color: #000; font-size:18px; text-decoration:underline; text-align:left; padding-bottom:5px;"> Personal Details</h1>


   <table width="90%" border="0">
     <tr>
       <td width="40%"><label for="name"> <span class="colored">*</span>Mr./Ms./Mrs.</label></td>
       <td width="60%"><input  type="text" name="name" maxlength="50" size="40%"></td>
     </tr>
     <tr>
       <td><label for="name"><span class="colored">*</span>Designation:</label></td>
       <td><input  type="text" name="desg" maxlength="50" size="40%"></td>
     </tr>
     <tr>
       <td><label for="name"><span class="colored">*</span>Company Name:</label></td>
       <td><input  type="text" name="compname" maxlength="50" size="40%"></td>
     </tr>
     <tr>
       <td><label for="name"><span class="colored">*</span>Address:</label></td>
       <td> <textarea  name="address" maxlength="1000" cols="42" rows="2"></textarea></td>
     </tr>
     <tr>
       <td><label for="name"><span class="colored">*</span>Email:</label></td>
       <td><input  type="text" name="email" maxlength="80" size="40%"></td>
     </tr>

   </table>



       <div class="center" style="padding-left:20%; padding-top:4%;">                     
       <button class="button2" name="submit" type="submit" value="Submit"><span>Send Message</span></button>
      </div>   
  </form>      

The sentfrommail.php is given below

    <?php

$EmailFrom = "mymail@site.com";
$EmailTo = "editor@mysite.com";
$Subject = "New Enquiry";
$name = Trim(stripslashes($_POST['name'])); 
$desg = Trim(stripslashes($_POST['desg'])); 
$compname = Trim(stripslashes($_POST['compname'])); 
$address = Trim(stripslashes($_POST['address'])); 
$email = Trim(stripslashes($_POST['email'])); 



// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Designation: ";
$Body .= $desg;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $compname;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $address;
$Body .= "\n";

$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

The form is not submitting. Its showing the 404 page not found error. What Am I doing wrong?

i also used this method

    <?PHP
/*
    Contact Form from HTML Form Guide
    This program is free software published under the
    terms of the GNU Lesser General Public License.
    See this page for more info:

*/
require_once("http://www.example.com/include/fgcontactform.php");

$formproc = new FGContactForm();


//1. Add your email address here.
//You can add more than one receipients.
$formproc->AddRecipient('editor@mysite.com'); //<<---Put your email address here


//2. For better security. Get a random tring from this link: 
// and put it here
$formproc->SetFormRandomKey('CnRrspl1FyEylUj');


if(isset($_POST['submitted']))
{
   if($formproc->ProcessForm())
   {
        $formproc->RedirectToURL("thank-you.php");
   }
}

?>

and the fgcontactform.php includes phpmailer. still getting the page not found error Thank You

Teju P
  • 1
  • 2

1 Answers1

0

I went through your code. It executes perfectly. I got a 404 Not found because I did not have a page called contactthanks.php which you are redirecting to.

Here is a sample code to send an Email :

<?php
$error=''; // Variable To Store Error Message
// Define $username and $password
$name=$_POST['name'];

$email=$_POST['email'];

$designation=$_POST['designation'];

$companyName=$_POST['companyName'];

$address=$_POST['address'];

sendEmail($email,$name,$company,$designation,$companyName,$address);
header( "Refresh:2; url=../index.php", true, 303);
mysqli_close($connection);

function sendEmail($email,$enquiryID,$name,$company,$sub) 
{
    $to = $email; // If you want the user to get the email then make no changes otherwise change this email to the Email ID you want to send an email to.

    $subject = 'Welcome to Your Application';

    $headers = "From: " . "Your Company Name<noreply@domain.com>" . "\r\n"; // Please make sure you have an active email id you add here instead of "noreply@domain.com" which has the MX records indexed to your hosting.
    // The idea is that you should be able to send an email from the hosting server via your domain.

    $headers .= "MIME-Version: 1.0\r\n";

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


    $message = '
                    <b>Name : </b>'.$name.'<br>
                    <b> Company : </b>'.$company.'<br>
                    <b> Email : </b>'.$email.'<br>
                    <b> Address : </b>'.$address.'<br><br>
                    <b> Designation : </b'.$designation.' <br>
    ';
    mail($to, $subject, $message, $headers);
}


?>
Aaditya Damani
  • 355
  • 1
  • 2
  • 12
  • I tried your code. It's not showing me any error. But it's not sending any mail either. The code i have given is working on another site except this one. i also checked server logs n setting. they also seems fine. – Teju P Jul 17 '17 at 06:05
  • Your server has to be configured to send outgoing email. I am assuming your domain's MX records have the servers outgoing entries. If you are on Godaddy : https://in.godaddy.com/help/add-an-mx-record-19234 – Aaditya Damani Jul 18 '17 at 06:26
  • yes, it was configured as Remote Mail Exchanger , that was the problem. now its perfectly working. Thank you. – Teju P Jul 18 '17 at 07:07
  • Glad to be of help! – Aaditya Damani Jul 18 '17 at 08:04