2019-09-20 20:00:42 (edited by Boo15mario 2019-09-20 20:59:37)

When I go to fill out the form it works but I don't get an email about the contact information in a email. I do see the sucess page when I press the submit button.
Here is the html part of the form

            <form method="post" action="contactengine.php">
                <label for="Name">Name:</label>
                <input type="text" name="Name" id="Name" />
<br> <br>
                <label for="Email">Email:</label>
                <input type="text" name="Email" id="Email" />
<br>
                <label for="Message">Message:</label><br />
                <textarea name="Message" rows="20" cols="20" id="Message"></textarea>

                <input type="submit" name="submit" value="Submit" class="submit-button" />
            </form>

and here is the PHP part of the form

<?php

$EmailFrom = "[email protected]";
$EmailTo = "[email protected]";
$Subject = "Nice & Simple Contact Form by CSS-Tricks";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));

// 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 .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$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\">";
}
?>

2019-09-21 19:54:00

Do you have sendmail or postfix on your system, if not, that may be where your problem is. I'll have to look at your code again to see what's going on if anything and if you do have everything installed and working, check and see if you have a FQDN up and running as mail servers don't like with an misconfigured FQDN setup. Also, check your logs. You also have not told us what system you're running or anything so I'm guestamating only from my experience here with issues I've had in the passt with servers in the like.

Jonathan Candler, A.K.A, Jonnyboy

2019-09-22 18:00:41

I am using

https://infinityfree.net

to host my website. Do you have any experience with this hosting company? So far I like their service.

2019-09-23 09:47:05

I recommend to use something like PHPMailer.

2019-09-23 19:08:07

Hello, at post 3, no I never used them as a hosting service, I'm running my own stuff.

Jonathan Candler, A.K.A, Jonnyboy

2019-09-25 04:56:12

Can you provide an example to how I can convert my php code to work for PHPMailer? So I can better understand how to get the information from the form to a usable email message. This has been very challenging for me as I am getting into php for the first time.

Thanks a lot for helping me

2019-09-25 05:20:39

I'd recommend you use SMTP2Go. You get SMTP credentials; all you need is sendmail.
The most likely problem your facing is not having postfix (unless your using shared hosting). If your using a VPS, set up postfix for outgoing email only (its not that hard). Otherwise, just call the mail()/sendmail() functions in your PHP script.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2019-10-03 05:33:57 (edited by Thatguy 2019-10-03 05:35:02)

I went through this same thing a while ago. I wrote a php thing to send an email which would happen when I pressed the submit button in an HTML form. The form had no data, it was just a post action to the page which contained my mail script. So I executed it to see if it would email me. When it did, I figured out my problem. Well actually I figured out a couple of my problems.
1. Gmail is gay. It marks stuff as spam that isn't spam but is interpreted by google as such because I didn't use an email address that had permission from its domain to be sent from by me. So if you haven't, check your spam folder.
2. I designed a small form with about three fields and a submit button, and wrote some PHP to send its contents to my inbox. I wrote all the php code awesomely and just like you I saw a success message but no email went anywhere because I'd forgot the most important part of my script, which was the actual function that sends the email. I defined all the variables and set them to correspond to my input fields and never did anything with them. Your code looks like it does that, with
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
That isn't how I'd write it, but it looks like it would get the job done. If you'd like my test script to make sure you can send mail from your hosts server, let me know.

-
That Guy. Serving those people since that time. To contact, use that info.

2019-10-04 19:59:53

@8 I would like to use your script to test my web server. This would help me a lot.