Contact Page


#1

Hello,

I just started coding last year, and in the last month have started to learn PHP. I’m trying to create a Contact Page on my website, but I’m missing something. I think I understand the error, but I don’t understand why the email isn’t being sent. Any help is very much appreciated.

Vince

The link is http://www.jazasolutions.com/JazaSolutionsContact.html

Jaza Solutions - Contact
"Jaza

Jaza Solutions

9818 Ushers Place

Waldorf, MD 20601


301-861-2133

info@jazasolutions.com

Get the Management Certification you need to make the next step in your career!


SEND A MESSAGE

; SEND MAIL
<?php if (isset($_POST['submit'])) { $name = $_POST['name']; $subject = $_POST['subject']; $mailFrom = $_POST['mail']; $message = $_POST['message'];
		$mailTo = "pmckeown@jazasolutions.com";
		$headers = "From:  ".$mailFrom;
		$txt = "You have received an email from ".$name.".\n\n".$message;
	
		mail($mailTo, $subject, $txt, $headers);
		header("Location: index.php?mailsend");
	}
?>
</body>

#2

very dangerous to use a mailer without sanitizing and checking for spam injection.
you seem to have the php code contained within the body of an html page.
the form cannot submit the data to this code in the html body.
separate the html from the contactform.php

JazaSolutionsContact.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Jaza Solutions - Contact</title>
    <link rel="stylesheet" type="text/css" href = "jazasolutions.css" />
    <script type="text/javascript" src="jazasolutions.js">return void(0);</script>
</head>
<body>
      <div id="header"><img src="jazasolutions.png" alt="Jaza Solutions, LLC"></div>
      <div id="nav">
         <ul>
            <li><a href=JazaSolutionsContact.html>Contact</a></li>
            <li><a href=JazaSolutionsAboutUs.html>About Us</a></li>
            <li><a href=JazaSolutionsCourses.html>Courses</a></li>
            <li><a href=JazaSolutions.html>Home</a></li>
         </ul>
      </div>
      <div class="sideRight">
         <p>Jaza Solutions</p><p>9818 Ushers Place</p><p>Waldorf, MD 20601</p><br><p>301-861-2133</p><p>info@jazasolutions.com</p>
      </div>
      <div class="main">
         <p>Get the Management Certification you need to make the next step in your career! </p><br>
         <p>SEND A MESSAGE</p>   
         <form class="contact-form" action="contactform.php" method="post">;
            <input type="text" name="name" placeholder="Full Name">
            <input type="text" name="mail" placeholder="Email">
            <input type="text" name="subject" placeholder="Subject">
            <textarea name="message" placeholder="Message"></textarea>
            <button type="submit" name="submit">SEND MAIL</button>
         </form>
      </div>
</body>
</html>

--------------------------------------------------------------------------------

contactform.php
<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") { //else GET outta here

  if (isset($_POST['submit'])) { //using a form token is also a good idea

    $cleanemail = filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL);
    $newemail = str_ireplace(array("\r", "\n", '%0A', '%0D'), '', $cleanemail);
    $cleansubject = sanitizeString($_POST['subject']);
    $newsubject = str_ireplace(array("\r", "\n", '%0A', '%0D'), '', $cleansubject);

    $name = sanitizeString($_POST['name']);
    $subject = $newsubject;
    $mailfrom = $newemail;
    $message = sanitizeString($_POST['message']);

    $mailTo = "pmckeown@jazasolutions.com";
    $headers = "From:  " . $mailFrom;
    $txt = "You have received an email from " . $name . "\n\n" . $message;

    mail($mailTo, $subject, $txt, $headers);
    header("Location: thankyoupage.php");
    exit;
    
  } else {
    // handle not isset error
    echo 'please use my form submit button.';
    exit;
  }

    function sanitizeString($s) {
        $s = trim($s);
        $s = stripslashes($s);
        $s = filter_var($s, FILTER_SANITIZE_STRING, ENT_QUOTES);
        $s = htmlspecialchars($s);
      return $s;
    }

    function sanitizeNumber($n) { // for use with integer values
        $n = trim($n);
        $n = stripslashes($n);
        $n = filter_var($n, FILTER_SANITIZE_NUMBER_INT);
        $n = htmlspecialchars($n);
      return $n;
    }

} else {
  //place error data here
  echo 'invalid request method.';
  exit;
}
?>

are you sure that you have an smtp server?
try the new approach with cleaned up code and a separate php page.
make sure that the “contactform.php” file contains the mail code that the html form submits.

hopefully you can make it work. I think that eventually, someone else will post here with better tips for you…