Jump to content

Problem with simple php email script


Hamish

Recommended Posts

Hi All,

 

I have the following email script which I can't get to work, please can anyone see where I am going wrong.

 

Regards

 

Hamish

 

<?php

//Check whether the submission is made
if(isset($hidSubmit)){

//Declarate the necessary variables
$mail_to=$txtEmailto;
$mail_from=$txtEmailfrm;
$mail_sub=$txtSub;
$mail_mesg=$txtMsg;

//Check for success/failure of delivery 
if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from"))
echo "<span class='textred'>E-mail has been sent successfully from $mail_sub to $mail_to</span>";
else
echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<title>Untitled Document</title>
</head>
<body>



<form name="frmsendmail" method="post" action="" onSubmit="return ValidationForm()">
      <table width="100%"  border="0">
        <tr>
         <td width="33%" align="right" class="text">To : 
          <td width="67%"><input name="txtEmailto2" type="text" class="input" id="txtEmailto22" size="30" maxlength="100">
        </tr>
        <tr>
          <td align="right" class="text">From : 
          <td><input name="txtEmailfrm2" type="text" class="input" id="txtEmailfrm22" size="30" maxlength="100">
        </tr>
        <tr>
          <td align="right" class="text">Subject : 
        <td><input name="txtSub2" type="text" class="input" id="txtSub22" size="30" maxlength="100">
        </tr>
        <tr>
          <td align="right" class="text">Mesage(body) : 
         <td><textarea name="txtMsg" cols="50" rows="10" class="input" id="textarea"></textarea>
        </tr>
      <tr>
          <td align="right"><input name="hidSubmit" type="hidden" id="hidSubmit" value="true">
              <input name="Submit" type="submit" class="input" value="Send">
          <td><input name="Submit2" type="reset" class="input" value="Reset">
        </tr>         
      </table>
     </form>
                
</body>
</html>

Link to comment
Share on other sites

There must be a simple answer to it I, I thought it may have been a copy and paste problem so tried again, but it makes no difference, am still getting "failed to send message from" somebody must have hit this snag before.

I would be grateful for any help.

 

Regards

 

Hamish

Link to comment
Share on other sites

See if this will work for you. There is no form field validation/error checking here. If you want to require fields, tell me which ones and I will add the code in. (The code is in the body instead)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />

<title>Untitled Document</title>

</head>

<body>

 

<?php

//Check whether the submission is made

if (!empty($_POST) {

 

  //Declarate the necessary variables

  $mail_to=$txtEmailto;

  $mail_from=$txtEmailfrm;

  $mail_sub=$txtSub;

  $mail_mesg=$txtMsg;

 

  mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/are/nReply-to:$mail_from");

  echo = "<p align=\"center\" class=\"textred\">E-mail has been sent successfully from $mail_sub to $mail_to</p>";

} else { ?>

 

<form name="frmsendmail" method="post" action="">

      <table width="100%"  border="0">

        <tr>

         <td width="33%" align="right" class="text">To :

          <td width="67%"><input name="txtEmailto2" type="text" class="input" size="30" maxlength="100">

        </tr>

        <tr>

          <td align="right" class="text">From :

          <td><input name="txtEmailfrm2" type="text" class="input" size="30" maxlength="100">

        </tr>

        <tr>

          <td align="right" class="text">Subject :

        <td><input name="txtSub2" type="text" class="input" size="30" maxlength="100">

        </tr>

        <tr>

          <td align="right" class="text">Mesage(body) :

         <td><textarea name="txtMsg" cols="50" rows="10" class="input"></textarea>

        </tr>

      <tr>

          <td align="right">

              <input name="Submit" type="submit" class="input" value="Send">

          <td><input name="Submit2" type="reset" class="input" value="Reset">

        </tr>         

      </table>

     </form>

 

}//end if !empty POST

Link to comment
Share on other sites

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.