My PHP form will not send email or give me an error

  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

another quick question. i am sure its easy.
what i am trying to do is if the domain is correct from the $_GET['d'] then i want it to display the email form. it does display the form but it will not send the email or give me an error. Also eventually the final if d=whatever will have multiple domains.

for instance $domain = $_GET['d'];
Code: [ Select ]
if($domain== "mydomain"){echo "<h2>$domain.com Is for sale.</h2><br>";sendmail($domain);}
else if($domain== "mydomain2"){echo "<h2>$domain.com Is for sale.</h2><br>";sendmail($domain);}
else if($domain== "mydomain3"){echo "<h2>$domain.com Is for sale.</h2><br>";sendmail($domain);}
  1. if($domain== "mydomain"){echo "<h2>$domain.com Is for sale.</h2><br>";sendmail($domain);}
  2. else if($domain== "mydomain2"){echo "<h2>$domain.com Is for sale.</h2><br>";sendmail($domain);}
  3. else if($domain== "mydomain3"){echo "<h2>$domain.com Is for sale.</h2><br>";sendmail($domain);}


this is what i currently have
PHP Code: [ Select ]
   <? $domain = $_GET['d'];
                                  function sendmail($domain){
                                  function spamcheck($field)
  {
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);
  if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }
if (isset($_REQUEST['email']))
  {$mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==FALSE)
    {
     echo "<div align='center'>There was an error in sending your email. Please try again.<br><a href='".$domain."'>Click here to go back.</a></div";
    }
  else
    {
    $email = $_REQUEST['email'] ;
    $message = $_REQUEST['message'] ;
   $mailedby = "-fNoReply@LilNetwork.com" ;
   $name = $_REQUEST['name'];
   $domain = $_REQUEST['domain'];
   $offer = $_REQUEST['offer'];
   $body = "From ".$name.",\n"
          ."Subject: ".$domain."\n"
             ."Domain: ".$Domain."\n"
             ."Offer: ".$offer."\n"
             ."Message:".$message."\n\n"
             ."This message has been sent via LilNetwork.com";
 
    mail("admin@lilnetwork.com", "Domain Sales VIA Lilnetwork website",
    $body, "From: $email",$mailedby );
    echo "<div align='center'>Thank you for using our mail form.<br><a href='".$domain."'>Click here to go back.</a></div>";
    }
  }
else
  {
   echo "<form action='' enctype='multipart/form-data' style='margin:0px; padding:0px '>
                                     <table width='248' border='1'>
   <tr>
     <td width='238'>Name:
     <input type='text' name='name' id='name'></td>
   </tr>
   <tr>
     <td>Email:
     <input name='email' type='text' id='email'></td>
   </tr>
   <tr>
     <td>Domain:
     <input name='domain' type='text' disabled id='domain' value='".$domain."' readonly='readonly'></td>
   </tr>
   <tr>
     <td>Offer:
     <input name='offer' type='text' id='offer' value='$'></td>
   </tr>
   <tr>
     <td>Message:
     <textarea name='message' id='message' cols='45' rows='5'></textarea></td>
   </tr>
   <tr>
     <td><input type='reset' name='Reset' id='button' value='Reset'>
     <input type='submit' name='button2' id='button2' value='Submit'></td>
   </tr>
 </table>
                                    </form>
                                    ";}
                                    };
                                   
                                    if($domain== "mydomain"){echo "<h2>$domain.com Is for sale.</h2><br>";sendmail($domain);}
else if($domain== "mydomain2"){echo "<h2>$domain.com Is for sale.</h2><br>";sendmail($domain);}
else if($domain== "mydomain3"){echo "<h2>$domain.com Is for sale.</h2><br>";sendmail($domain);}
else {echo"We are sorry but we cannot find what you are looking for.";} ?>
  1.    <? $domain = $_GET['d'];
  2.                                   function sendmail($domain){
  3.                                   function spamcheck($field)
  4.   {
  5.   $field=filter_var($field, FILTER_SANITIZE_EMAIL);
  6.   if(filter_var($field, FILTER_VALIDATE_EMAIL))
  7.     {
  8.     return TRUE;
  9.     }
  10.   else
  11.     {
  12.     return FALSE;
  13.     }
  14.   }
  15. if (isset($_REQUEST['email']))
  16.   {$mailcheck = spamcheck($_REQUEST['email']);
  17.   if ($mailcheck==FALSE)
  18.     {
  19.      echo "<div align='center'>There was an error in sending your email. Please try again.<br><a href='".$domain."'>Click here to go back.</a></div";
  20.     }
  21.   else
  22.     {
  23.     $email = $_REQUEST['email'] ;
  24.     $message = $_REQUEST['message'] ;
  25.    $mailedby = "-fNoReply@LilNetwork.com" ;
  26.    $name = $_REQUEST['name'];
  27.    $domain = $_REQUEST['domain'];
  28.    $offer = $_REQUEST['offer'];
  29.    $body = "From ".$name.",\n"
  30.           ."Subject: ".$domain."\n"
  31.              ."Domain: ".$Domain."\n"
  32.              ."Offer: ".$offer."\n"
  33.              ."Message:".$message."\n\n"
  34.              ."This message has been sent via LilNetwork.com";
  35.  
  36.     mail("admin@lilnetwork.com", "Domain Sales VIA Lilnetwork website",
  37.     $body, "From: $email",$mailedby );
  38.     echo "<div align='center'>Thank you for using our mail form.<br><a href='".$domain."'>Click here to go back.</a></div>";
  39.     }
  40.   }
  41. else
  42.   {
  43.    echo "<form action='' enctype='multipart/form-data' style='margin:0px; padding:0px '>
  44.                                      <table width='248' border='1'>
  45.    <tr>
  46.      <td width='238'>Name:
  47.      <input type='text' name='name' id='name'></td>
  48.    </tr>
  49.    <tr>
  50.      <td>Email:
  51.      <input name='email' type='text' id='email'></td>
  52.    </tr>
  53.    <tr>
  54.      <td>Domain:
  55.      <input name='domain' type='text' disabled id='domain' value='".$domain."' readonly='readonly'></td>
  56.    </tr>
  57.    <tr>
  58.      <td>Offer:
  59.      <input name='offer' type='text' id='offer' value='$'></td>
  60.    </tr>
  61.    <tr>
  62.      <td>Message:
  63.      <textarea name='message' id='message' cols='45' rows='5'></textarea></td>
  64.    </tr>
  65.    <tr>
  66.      <td><input type='reset' name='Reset' id='button' value='Reset'>
  67.      <input type='submit' name='button2' id='button2' value='Submit'></td>
  68.    </tr>
  69.  </table>
  70.                                     </form>
  71.                                     ";}
  72.                                     };
  73.                                    
  74.                                     if($domain== "mydomain"){echo "<h2>$domain.com Is for sale.</h2><br>";sendmail($domain);}
  75. else if($domain== "mydomain2"){echo "<h2>$domain.com Is for sale.</h2><br>";sendmail($domain);}
  76. else if($domain== "mydomain3"){echo "<h2>$domain.com Is for sale.</h2><br>";sendmail($domain);}
  77. else {echo"We are sorry but we cannot find what you are looking for.";} ?>
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I am not sure if this is the cause of the problem, but on your form your are not specifying a method or an action. I would recommend you put your method as POST here. So:

HTML Code: [ Select ]
<form action='nameofscript.php' enctype='multipart/form-data' style='margin:0px; padding:0px' method="post">


Secondly I notice you are using $_REQUEST vs $_GET or $_POST. I would recommend not using $_REQUEST and just get the varibles via the method you plan to use. Overall this tends to make scripts more secure as a $_REQUEST combines COOKIE, GET, AND POST with COOKIE data always taking precedence.

Finally it looks like you have your spamcheck function inside of your sendmail function. I would separate that out of the sendmail function as it might cause scope issues. A variable declared in the outer function will not be visible in the inner function unless you make the variable global inside that inner function. I don't think you are doing that here, but it can make things confusing.

Hopefully that gives you a place to start, maybe one of these issues will resolve your problem, let us know your new updated code and if the problem still exists.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

well its fixed now
PHP Code: [ Select ]
 
                              <? function spamcheck($field){
                           $field=filter_var($field, FILTER_SANITIZE_EMAIL);
                              if(filter_var($field, FILTER_VALIDATE_EMAIL)){
                                 return TRUE;
                              }else{
                                    return FALSE;
                              }
                         }/*End spamcheck*/
 
 
                        function sendmail($domain){
                           if (isset($_POST['email'])){
                              $mailcheck = spamcheck($_POST['email']);
                              if ($mailcheck==FALSE){
                                 echo "<div align='center'>There was an error in sending your email. Please try again.<br><a href='contactus.php'>Click here to go back.</a></div";
                              }else {
                                 $email = $_POST['email'] ;
                                 $message = $_POST['message'] ;
                                 $mailedby = "-fNoReply@LilNetwork.com" ;
                                 $name = $_POST['name'];
                                 $domain = $_POST['domain'];
                                 $offer = $_POST['offer'];
                                 $body = "From ".$name.",\n"
                                       ."Domain: ".$domain."\n"
                                       ."Offer: ".$offer."\n"
                                       ."Message:".$message."\n\n"
                                       ."This message has been sent via LilNetwork.com";
                                 mail("admin@lilnetwork.com", "Domain Sales VIA Lilnetwork website", $body, "From: $email",$mailedby );
                                 echo "<div align='center'>Thank you for using our mail form.<br><a href='".$domain."'>Click here to go back.</a></div>";
                              }
                           }else{
                                           echo "<form method='POST' enctype='multipart/form-data' style='margin:0px; padding:0px '>
                                       <table width='248' border='1'>
                                          <tr>
                                             <td width='238'>Name:<input type='text' name='name' id='name'></td>
                                          </tr>
                                          <tr>
                                             <td>Email: <input name='email' type='text' id='email'></td>
                                          </tr>
                                          <tr>
                                             <td>Domain: <input name='domain' type='text' id='domain' value='".$domain."' readonly='readonly'></td>
                                          </tr>
                                          <tr>
                                             <td>Offer: <input name='offer' type='text' id='offer' value='$'></td>
                                          </tr>
                                          <tr>
                                             <td>Message: <textarea name='message' id='message' cols='45' rows='5'></textarea></td>
                                          </tr>
                                          <tr>
                                             <td><input type='reset' name='Reset' id='button' value='Reset'> <input type='submit' name='button2' id='button2' value='Submit'></td>
                                          </tr>
                                       </table>
                                    </form>";
                           } /*End mailcheck*/
                                     
                        }/*end sendmail*/
                        $domain = $_GET['domain'];
                           if($domain== "testdomain"){
                              echo "<h2>$domain.com Is for sale.</h2><br>";
                              sendmail($domain);
                           }else{
                           echo "Coming Soon!";
                           }
                           ?>
 
  1.  
  2.                               <? function spamcheck($field){
  3.                            $field=filter_var($field, FILTER_SANITIZE_EMAIL);
  4.                               if(filter_var($field, FILTER_VALIDATE_EMAIL)){
  5.                                  return TRUE;
  6.                               }else{
  7.                                     return FALSE;
  8.                               }
  9.                          }/*End spamcheck*/
  10.  
  11.  
  12.                         function sendmail($domain){
  13.                            if (isset($_POST['email'])){
  14.                               $mailcheck = spamcheck($_POST['email']);
  15.                               if ($mailcheck==FALSE){
  16.                                  echo "<div align='center'>There was an error in sending your email. Please try again.<br><a href='contactus.php'>Click here to go back.</a></div";
  17.                               }else {
  18.                                  $email = $_POST['email'] ;
  19.                                  $message = $_POST['message'] ;
  20.                                  $mailedby = "-fNoReply@LilNetwork.com" ;
  21.                                  $name = $_POST['name'];
  22.                                  $domain = $_POST['domain'];
  23.                                  $offer = $_POST['offer'];
  24.                                  $body = "From ".$name.",\n"
  25.                                        ."Domain: ".$domain."\n"
  26.                                        ."Offer: ".$offer."\n"
  27.                                        ."Message:".$message."\n\n"
  28.                                        ."This message has been sent via LilNetwork.com";
  29.                                  mail("admin@lilnetwork.com", "Domain Sales VIA Lilnetwork website", $body, "From: $email",$mailedby );
  30.                                  echo "<div align='center'>Thank you for using our mail form.<br><a href='".$domain."'>Click here to go back.</a></div>";
  31.                               }
  32.                            }else{
  33.                                            echo "<form method='POST' enctype='multipart/form-data' style='margin:0px; padding:0px '>
  34.                                        <table width='248' border='1'>
  35.                                           <tr>
  36.                                              <td width='238'>Name:<input type='text' name='name' id='name'></td>
  37.                                           </tr>
  38.                                           <tr>
  39.                                              <td>Email: <input name='email' type='text' id='email'></td>
  40.                                           </tr>
  41.                                           <tr>
  42.                                              <td>Domain: <input name='domain' type='text' id='domain' value='".$domain."' readonly='readonly'></td>
  43.                                           </tr>
  44.                                           <tr>
  45.                                              <td>Offer: <input name='offer' type='text' id='offer' value='$'></td>
  46.                                           </tr>
  47.                                           <tr>
  48.                                              <td>Message: <textarea name='message' id='message' cols='45' rows='5'></textarea></td>
  49.                                           </tr>
  50.                                           <tr>
  51.                                              <td><input type='reset' name='Reset' id='button' value='Reset'> <input type='submit' name='button2' id='button2' value='Submit'></td>
  52.                                           </tr>
  53.                                        </table>
  54.                                     </form>";
  55.                            } /*End mailcheck*/
  56.                                      
  57.                         }/*end sendmail*/
  58.                         $domain = $_GET['domain'];
  59.                            if($domain== "testdomain"){
  60.                               echo "<h2>$domain.com Is for sale.</h2><br>";
  61.                               sendmail($domain);
  62.                            }else{
  63.                            echo "Coming Soon!";
  64.                            }
  65.                            ?>
  66.  

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: Liamw411 and 69 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.