Jump to content

Recommended Posts

Hi,

 

I am new to PHP though I have managed to get it installed and running on a Windows XP machine.  I am having difficulties in sending data from forms to an eMail recipient.  I found a script which runs but it always reports that the mail has failed to send.

 

Has anyone had any similar problems and how could I overcome this problem?

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"

"http://www.w3.org/TR/REC-html40/loose.dtd">

<html>

<head>

<title>Contact Form</title>

<meta http-equiv="Content-Type"

  content="text/html; charset=iso-8859-1">

</head>

<body>

<?php

  if ($_SERVER['REQUEST_METHOD'] != 'POST'){

      $me = $_SERVER['PHP_SELF'];

?>

  <form name="form1" method="post"

        action="<?php echo $me;?>">

      <table border="0" cellspacing="0" cellpadding="2">

        <tr>

            <td>Name:</td>

            <td><input type="text" name="Name"></td>

        </tr>

        <tr>

            <td>Subject</td>

            <td><input type="text" name="Subject"></td>

        </tr>

        <tr>

            <td valign="top">Message:</td>

            <td><textarea name="MsgBody"></textarea></td>

        </tr>

        <tr>

            <td> </td>

            <td><input type="submit" name="Submit"

              value="Send"></td>

        </tr>

      </table>

  </form>

<?php

  } else {

      error_reporting(0);

      $recipient = me@myemail.co.uk';

      $subject = stripslashes($_POST['Subject']);

      $from = stripslashes($_POST['Name']);

      $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);

      if (mail($recipient, $subject, $msg))

        echo nl2br("<b>Message Sent:</b>

        To: $recipient

        Subject: $subject

        Message:

        $msg");

      else

        echo "Message failed to send";

}

?>

</body>

</html>

 

 

is the code.  The error screen just says "Message failed to send"

 

It is running at http://213.120.121.64/allan.php

php.ini reads

 

[mail function]

; For Win32 only.

SMTP = localhost

smtp_port = 25

 

for the mail server......

 

the script now looks like this:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"

  "http://www.w3.org/TR/REC-html40/loose.dtd">

<html>

<head>

<title>Contact Form</title>

<meta http-equiv="Content-Type"

  content="text/html; charset=iso-8859-1">

</head>

<body>

<?php

  if ($_SERVER['REQUEST_METHOD'] != 'POST'){

      $me = $_SERVER['PHP_SELF'];

?>

  <form name="form1" method="post"

        action="<?php echo $me;?>">

      <table border="0" cellspacing="0" cellpadding="2">

        <tr>

            <td>Name:</td>

            <td><input type="text" name="Name"></td>

        </tr>

        <tr>

            <td>Subject</td>

            <td><input type="text" name="Subject"></td>

        </tr>

        <tr>

            <td valign="top">Message:</td>

            <td><textarea name="MsgBody"></textarea></td>

        </tr>

        <tr>

            <td> </td>

            <td><input type="submit" name="Submit"

              value="Send"></td>

        </tr>

      </table>

  </form>

<?php

  } else {

      error_reporting(0);

      $recipient = me@myemail.co.uk';

      $subject = stripslashes($_POST['Subject']);

      $from = stripslashes($_POST['Name']);

      $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);

      if (mail($recipient, $subject, $msg))

        echo nl2br("Message Sent:

        To: $recipient

        Subject: $subject

        Message:

        $msg");

      else

        echo "Message failed to send";

}

?>

</body>

</html>

 

oops sorry am working with a remote PC to add to problems - never downloaded remote PC clipboard!

 

Here it is

 

<head>

<title>Contact Form</title>

<meta http-equiv="Content-Type"

  content="text/html; charset=iso-8859-1">

</head>

<body>

<?php

  if ($_SERVER['REQUEST_METHOD'] != 'POST'){

      $me = $_SERVER['PHP_SELF'];

?>

  <form name="form1" method="post"

        action="<?php echo $me;?>">

      <table border="0" cellspacing="0" cellpadding="2">

        <tr>

            <td>Name:</td>

            <td><input type="text" name="Name"></td>

        </tr>

        <tr>

            <td>Subject</td>

            <td><input type="text" name="Subject"></td>

        </tr>

        <tr>

            <td valign="top">Message:</td>

            <td><textarea name="MsgBody"></textarea></td>

        </tr>

        <tr>

            <td> </td>

            <td><input type="submit" name="Submit"

              value="Send"></td>

        </tr>

      </table>

  </form>

<?php

  } else {

      error_reporting(0);

      $recipient = 'me@myemail.co.uk';

      $subject = stripslashes($_POST['Subject']);

      $from = stripslashes($_POST['Name']);

      $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);

      {if (mail($recipient, $subject, $msg))

        echo nl2br("Message Sent:

        To: $recipient

        Subject: $subject

        Message:

        $msg");

      else

        echo "Message failed to send";}

}

?>

</body>

</html>

Try

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
   "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>Contact Form</title>
<meta http-equiv="Content-Type" 
   content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
   if ($_SERVER['REQUEST_METHOD'] != 'POST'){
      $me = $_SERVER['PHP_SELF'];
?>
   <form name="form1" method="post"
         action="<?php echo $me;?>">
      <table border="0" cellspacing="0" cellpadding="2">
         <tr>
            <td>Name:</td>
            <td><input type="text" name="Name"></td>
         </tr>
         <tr>
            <td>Subject</td>
            <td><input type="text" name="Subject"></td>
         </tr>
         <tr>
            <td valign="top">Message:</td>
            <td><textarea name="MsgBody"></textarea></td>
         </tr>
         <tr>
            <td> </td>
            <td><input type="submit" name="Submit"
               value="Send"></td>
         </tr>
      </table>
   </form>
<?php
   } else {
      error_reporting(0);
      $recipient = 'me@myemail.co.uk';
      $subject = stripslashes($_POST['Subject']);
      $from = stripslashes($_POST['Name']);
      $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);
      if (mail($recipient, $subject, $msg))
         echo nl2br("Message Sent:
         To: $recipient
         Subject: $subject
         Message:
         $msg");
   }else{
         echo "Message failed to send";
}
?>
</body>
</html>

For troubleshooting, make it easy

 

Create a new file and just do

 

<?php
mail("youremail@email.com", "Subject", "Body", "FROM: noone@email.com");
?>

 

Replace youremail@email.com with your real email.  If this doesnt work, its your mail server setup.

 

were missing brackets ;)

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
   "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>Contact Form</title>
<meta http-equiv="Content-Type" 
   content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
   if ($_SERVER['REQUEST_METHOD'] != 'POST'){
      $me = $_SERVER['PHP_SELF'];
?>
   <form name="form1" method="post"
         action="<?php echo $me;?>">
      <table border="0" cellspacing="0" cellpadding="2">
         <tr>
            <td>Name:</td>
            <td><input type="text" name="Name"></td>
         </tr>
         <tr>
            <td>Subject</td>
            <td><input type="text" name="Subject"></td>
         </tr>
         <tr>
            <td valign="top">Message:</td>
            <td><textarea name="MsgBody"></textarea></td>
         </tr>
         <tr>
            <td> </td>
            <td><input type="submit" name="Submit"
               value="Send"></td>
         </tr>
      </table>
   </form>
<?php
   } else {
      error_reporting(0);
      $recipient = 'me@myemail.co.uk';
      $subject = stripslashes($_POST['Subject']);
      $from = stripslashes($_POST['Name']);
      $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);
      if (mail($recipient, $subject, $msg)){
         echo nl2br("Message Sent:
         To: $recipient
         Subject: $subject
         Message:
         $msg");}
   }else{
         echo "Message failed to send";
}
?>
</body>
</html>

Thank you so very much guys!

 

Got it sorted finally!  It was starting to stress me out!  Now all I gotta get hold of is a customer database/membership php and something to control access into a staff only area and I'll be sorted  ;D

 

THANKS

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.