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
https://forums.phpfreaks.com/topic/52322-problem-with-simple-php-email-script/
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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.