-6

This is my php code

<html>
<head>
<title>Joerassic Park</title>
</head>
<body>
<?php
$to = "joerassicpark.ddns@gmail.com";
$subject = "Contact For";
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$headers = "From: $email";
$sent = mail('joerassicpark.ddns@gmail.com',$subject,$message,$headers);
if($sent){
print('<a href="contact.html">Thank you. Click here to return to site.</a>');
} else {
print "There was an issue with your contact form";
}

?>
</body>
</html>

And you can see my errors at joerassicpark.ddns.net/contact.php

Can Anyone tell me what I am doing wrong?

JoerassicPark
  • 111
  • 1
  • 1
  • 6
  • 2
    Can you paste the errors at least? – taxicala Jun 02 '15 at 19:18
  • 2
    Please post your errors here so they are preserved with the question for future SO visitors. – Jay Blanchard Jun 02 '15 at 19:18
  • You can view the errors at the url I posted – JoerassicPark Jun 02 '15 at 19:27
  • here they are: ( ! ) Notice: Undefined index: name in C:\wamp\www\contact.php on line 9 Call Stack # Time Memory Function Location 1 0.0057 239744 {main}( ) ..\contact.php:0 ( ! ) Notice: Undefined index: email in C:\wamp\www\contact.php on line 10 Call Stack # Time Memory Function Location 1 0.0057 239744 {main}( ) ..\contact.php:0 – JoerassicPark Jun 02 '15 at 19:28
  • ( ! ) Notice: Undefined index: message in C:\wamp\www\contact.php on line 11 Call Stack # Time Memory Function Location 1 0.0057 239744 {main}( ) ..\contact.php:0 ( ! ) Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\contact.php on line 13 Call Stack # Time Memory Function Location 1 0.0057 239744 {main}( ) ..\contact.php:0 2 0.0245 241184 mail ( ) ..\contact.php:13 – JoerassicPark Jun 02 '15 at 19:28
  • 1
    You should edit the question and paste that in. Also, you have a page named `contact.html` and also a page named `contact.php`? That's perfectly valid of course, but still. – Mr Lister Jun 02 '15 at 19:28

1 Answers1

2

The errors are:

Notice: Undefined index: name in C:\wamp\www\contact.php on line 9
Notice: Undefined index: email in C:\wamp\www\contact.php on line 10
Notice: Undefined index: message in C:\wamp\www\contact.php on line 11
Warning: mail(): Failed to connect to mailserver at &quot;localhost&quot; port 25, verify your &quot;SMTP&quot; and &quot;smtp_port&quot; setting in php.ini or use ini_set() in C:\wamp\www\contact.php on line 13

You are assuming that those keys exist in the POST array.

This code should fix 3 of 4 errors.

<html>
<head>
<title>Joerassic Park</title>
</head>
<body>
<?php

$error = false;
$name = isset($_POST["name"]) ? $_POST["name"] : null;
$email = isset($_POST["email"]) ? $_POST["email"] : null;
$message = isset($_POST["message"]) ? $_POST["message"] : null;

if(is_null($name) || is_null($email) || is_null($message)) $error = true;

if(!$error) {
    $to = "joerassicpark.ddns@gmail.com";
    $subject = "Contact For";
    $headers = "From: $email";
    $sent = mail('joerassicpark.ddns@gmail.com',$subject,$message,$headers);
}

if(!$error && $sent){
    print('<a href="contact.html">Thank you. Click here to return to site.</a>');
} else {
    print "There was an issue with your contact form";
}

?>
</body>
</html>

However your last error indicates that you do not have a mail server configured.

This has been answered in a previous question here.

Community
  • 1
  • 1
Jim Wright
  • 5,905
  • 1
  • 15
  • 34