Hi there,

I've been using a contact form on my website for years, and it has worked fine (server was running PHP4). Yesterday I moved to a new server running PHP5 and my contact form no longer works. It doesn't display any errors when used, it just doesn't work (i.e.) no email ever gets sent to me.

If anyone can take a look at the code and help me get it working, I'll be very grateful.

<?

$name = stripslashes($_POST['name']);
$email = stripslashes($_POST['email']);
$tel = stripslashes($_POST['phonenumber']);
$msg = stripslashes($_POST['message']);

$recipient = "info@mysite.com";
$subject = stripslashes("Inquiry (via mysite.com)");
$ccsubject = stripslashes("Inquiry (CC from mysite.com)");

$mailheaders = "From: $_POST[name] <$_POST[email]> \n";
$mailheaders .= "Reply-To: $_POST[email]";

$body = "Name: $name\n";
$body .= "Phone number: $tel\n\n";
$body .= "Message:\n$msg";

  if (!isset($name) || !isset($email) || !isset($phonenumber) || !isset($message)) {
    header( "Location: /" );
  }
  elseif (empty($name) || empty($email) || empty($phonenumber) ||empty($message)) {
    header( "Location: /?msg=1#form" );
  }
  else {
    mail($recipient, $subject, $body, $mailheaders);
    header( "Location: /" );

if (isset($cc)) {
	    mail( $email, $ccsubject, $body, "From: info@mysite.com" );
}
header( "Location: /?msg=2#form" );
}

?>

    Could be that the current server requires that you set the From: mail header to a valid email address on that server in order to prevent spammers from using it to relay spam. You can still put the user's email in the Reply-To header.

    To help debug you might want to turn on all error reporting. Also, it's a good idea to use "<?php" instead of "<?" in case the short_open_tag option is not turned on.

    <?php
    ini_set('display_errors', 1); // set to 0 for production version
    error_reporting(E_ALL);
    // rest of script....
    ?>
    
      13 days later

      I created an email form page that uses PHP 4 or 4.5 (I am not sure which) and PHP 5, and it too will no longer send emails to the recipient email address since the web hosting company upgraded to PHP 5. :mad:

      I think there may be an upgraded version of the form available, we just have to hunt all over the web until we find it. Either that, or there is a simple line of code that we just have to paste somewhere on our page. Isn't that usually the solution? 😕

        Write a Reply...