Email Not being received from Contact form

Hi, I will be grateful for any assistance.

I am testing a simple Contact form on a website, using php to send the information on the form. The php program appears to run, as the confirmation message is displayed, but no email is received. I have tried several email addresses, but none seems to work. Can anyone please advise as to why the emails are not being sent? There is a mail server on the web server.

I got the codes from an internet tutorial site as I am very green on this:

CONTACT FORM Code:
<html>

<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=windows-1252”>
<meta name=“GENERATOR” content=“Microsoft FrontPage 4.0”>
<meta name=“ProgId” content=“FrontPage.Editor.Document”>
<title>New Page 1</title>
</head>

<body>
<form method=“POST” action=“mailer.php”>
<input type=“text” name=“name” size=“19”><br>
<br>
<input type=“text” name=“email” size=“19”><br>
<br>
<textarea rows=“9” name=“message” cols=“30”></textarea>
<br>
<br>
<input type=“submit” value=“Submit” name=“submit”>
</form>

</body>

</html>

PHP Code:

<?php
if(isset($_POST[‘submit’])) {
$to = “adviser@lamortgages.co.uk”;
$subject = “Form Tutorial”;
$name_field = $_POST[‘name’];
$email_field = $_POST[‘email’];
$message = $_POST[‘message’];

$body = “From: $name_field
E-Mail: $email_field
Message:
$message”;

echo “Data has been submitted to $to!”;
mail($to, $subject, $body);
} else {
echo “blarg!”;
}
?>

The contact page is at: LA Mortgage Solutions Contact US

Many thanks,

Leo

Hi, thank you very much for the reply. I have uploaded the revised code as advised. This shows that the mail() function is not succeeding in sending the email. What could be the reason for that? I have an Actinic Shopping cart on the same server, and emails are successfully sent from the website. That email protocol is implemented in perl.

Any further assistance will be appreciated.

Hmm… it could be anything but at least we now know that the mail() is not working.

Can you please post your current revised code.

Thanks. The revised code is:

<?php
if(isset($_POST[‘submit’]))
{
//Test for true / false from mail()
if (mail($to, $subject, $body))
{//True - success
echo “Data has been submitted to $to!”;
}
else
{//False - Not sent.
echo “Message could not be sent”;
}
}
?>

“Message could not be sent” is displayed when I click the Submit button.

You’re testing incorrectly.
You’re testing for the submit button and then outputting a success message.

mail() returns a boolean and this is the only way to correctly know if the function succeeded in sending email or not.

Try this:


if(isset($_POST['submit']))
   {
   //Test for true / false from mail()
   if (mail($to, $subject, $body))
      {//True - success
      echo "Data has been submitted to $to!"; 
      }
   else
      {//False - Not sent.
      echo "blarg!";
      }
   }


If that works then i suspect your mail server is incorrectly setup OR they’re being spam’d into the spam bin/trash. Either way you need to tell us how the above code works for you.

Sorry, please ignore the above. The revised code is:

<?php
if(isset($_POST[‘submit’]))
{
$to = “adviser@lamortgages.co.uk”;
$subject = “Form Tutorial”;
$name_field = $_POST[‘name’];
$email_field = $_POST[‘email’];
$message = $_POST[‘message’];

$body = “From: $name_field
E-Mail: $email_field
Message:
$message”;

//Test for true / false from mail()
if (mail($to, $subject, $body))
{//True - success
echo “Data has been submitted to $to!”;
}
else
{//False - Not sent.
echo “Message could not be sent”;
}
}
?>

“Message could not be sent” is displayed when I click the Submit button. Do you please have a code to trap any generated error? Thanks.

Aren’t you forgetting something? - like:
$to = “adviser@lamortgages.co.uk”;
$subject = “Form Tutorial”;
$name_field = $_POST[‘name’];
$email_field = $_POST[‘email’];
$message = $_POST[‘message’];

$body = “From: $name_field
E-Mail: $email_field
Message:
$message”;

???

I gave you sample code to copy / paste and edit into your script appropriately. Not to completely replace it. You should be able to see how my code works with yours.

Hi, I had realised that and amended the script appropriately. See above.

Well, this works perfectly on my local setup:


<?
if(isset($_POST['submit']))
   {
   $to = "******@yahoo.com";
   $subject = "Form Tutorial";
   $name_field = $_POST['name'];
   $email_field = $_POST['email'];
   $message = $_POST['message'];
 
$body = "From: $name_field\
 E-Mail: $email_field\
 Message:\
 $message";

   //Test for true / false from mail()
   if (mail($to, $subject, $body))
      {//True - success
      echo "Data has been submitted to $to!";
      }
   else
      {//False - Not sent.
      echo "Message could not be sent";
      }
   } 
?> 

Your email system must be wrongly configured OR you don’t have sendmail installed.

What system are you using? - linux, windows or mac?

If you’re on windows then you will need a program called fakesendmail.

It’s a Windows Server IIS 7.0. Does that mean fakesendmail needs to be installed on the server for it to work?

Yes… or equivalent.

Windows IIS is only a WEB server. That means it only serves WEB pages. It doesn’t do email afaik.

You will need to install fakesendmail and then setup the path to it in your php.ini file and then set up the settings in fakesendmails config file. Should take 10 mins tops :wink:

Note fakesendmail like normal sendmail only SENDS email. It doesn’t accept incoming mail send to your domain or ip address. For that you will need an SMTP server.

Thanks for your help. I do know there is a mail server installed. I have a shopping cart on the same server with a contact form. However this uses a perl script. There is also SMTP installed which I use for my outgoing emails. I will find out from the hosting company which mail server is installed.

But is the main server installed correctly in php.ini?

Something is a bit screwy there i’d say.

Just an update.

The server engineers have done something on the server and the scripts now work as expected. Unfortunately I am not privy to what corrective action was undertaken by them. I did allude to the possible issue with the php.ini file!

Many thanks for your assistance.

No worries, glad you got it working :wink: