Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Error while sending e-mail

Error while sending e-mail

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
helpphpcombusinessquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gagan 20
    wrote on last edited by
    #1

    Hi all. I am new to PHP and trying to learn it.I have created a web page and defined items as below :

    <form method="POST" action="send.php">
    <font color="green"> Full Name : </font>
    <input type="text" name="name" size="20">

      <font color="green"> Gotra(Clan) : </font>
      <input type="text" name="gotra" size="20">
    
      <font color="green"> Father's Name : </font>
      <input type="text" name="fname" size="20">
    
      <font color="green">Details of Prasad to be Offered : </font>
    

    (eg.: name of temple, quantity of prasad, specific date & any other requirements)
    <textarea rows="5" name="prasad" cols="40" ></textarea>

      <font color="green"> Any Wish to God  : </font>
      <textarea rows="5" name="wish" cols="40" ></textarea>
    
      <font color="green"> Postal Address : </font>
      <textarea rows="5" name="address" cols="40" ></textarea>
    
      <font color="green"> Phone no.  : </font>
      <input type="text" name="phone" size="20">
    
      <font color="green"> Preferred Time of Contact : </font>
      <input type="text" name="time" size="20">
    
      <font color="green"> Email address : </font> 
      <input type="text" name="email" size="20">
    
    <br>      
     <input name="Submit" type="submit" class="input" value="Send">
         <input name="Submit2" type="reset" class="input" value="Reset">
        </br>         
     </form>
    

    and the send.php has following block of code :

    <?php
    if(isset($_POST['submit'])) {
    $to = "gagan.u20@gmail.com";
    $subject = "E-Prasad Details";
    $name_field = $_POST['name'];
    $gotra_field=$_POST['gotra'];
    $fname_field = $_POST['fname'];
    $prasad=$_POST['prasad'];
    $wish=$_POST['wish'];
    $address=$_POST['address'];
    $phone_field=$_POST['phone'];
    $time_field=$_POST['time'];
    $email_field=$_POST['email'];

    $body = "From: $name_field\n Gotra: $gotra_field\n Father's name: $fname_field\n Details of prasad to be offered : $prasad\n Any wish to God: $wish\n Postal address : $address\n Phone no. : $phone_field\n Preferred time of contact : $time_field\n E-mail address : $email_field";

    echo "Data has been submitted!";
    mail($to, $subject, $body);
    } else {
    echo "An error occurred! Please try again.";
    }
    ?>

    Now the problem is, when I fill the form and cl

    D A 2 Replies Last reply
    0
    • G Gagan 20

      Hi all. I am new to PHP and trying to learn it.I have created a web page and defined items as below :

      <form method="POST" action="send.php">
      <font color="green"> Full Name : </font>
      <input type="text" name="name" size="20">

        <font color="green"> Gotra(Clan) : </font>
        <input type="text" name="gotra" size="20">
      
        <font color="green"> Father's Name : </font>
        <input type="text" name="fname" size="20">
      
        <font color="green">Details of Prasad to be Offered : </font>
      

      (eg.: name of temple, quantity of prasad, specific date & any other requirements)
      <textarea rows="5" name="prasad" cols="40" ></textarea>

        <font color="green"> Any Wish to God  : </font>
        <textarea rows="5" name="wish" cols="40" ></textarea>
      
        <font color="green"> Postal Address : </font>
        <textarea rows="5" name="address" cols="40" ></textarea>
      
        <font color="green"> Phone no.  : </font>
        <input type="text" name="phone" size="20">
      
        <font color="green"> Preferred Time of Contact : </font>
        <input type="text" name="time" size="20">
      
        <font color="green"> Email address : </font> 
        <input type="text" name="email" size="20">
      
      <br>      
       <input name="Submit" type="submit" class="input" value="Send">
           <input name="Submit2" type="reset" class="input" value="Reset">
          </br>         
       </form>
      

      and the send.php has following block of code :

      <?php
      if(isset($_POST['submit'])) {
      $to = "gagan.u20@gmail.com";
      $subject = "E-Prasad Details";
      $name_field = $_POST['name'];
      $gotra_field=$_POST['gotra'];
      $fname_field = $_POST['fname'];
      $prasad=$_POST['prasad'];
      $wish=$_POST['wish'];
      $address=$_POST['address'];
      $phone_field=$_POST['phone'];
      $time_field=$_POST['time'];
      $email_field=$_POST['email'];

      $body = "From: $name_field\n Gotra: $gotra_field\n Father's name: $fname_field\n Details of prasad to be offered : $prasad\n Any wish to God: $wish\n Postal address : $address\n Phone no. : $phone_field\n Preferred time of contact : $time_field\n E-mail address : $email_field";

      echo "Data has been submitted!";
      mail($to, $subject, $body);
      } else {
      echo "An error occurred! Please try again.";
      }
      ?>

      Now the problem is, when I fill the form and cl

      D Offline
      D Offline
      Dr Walt Fair PE
      wrote on last edited by
      #2

      Why do you check

      if(isset($_POST['submit']))

      ? Obviously that is false and you've trapped the problem and displayed the error message you wrote.

      CQ de W5ALT

      Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

      G 1 Reply Last reply
      0
      • D Dr Walt Fair PE

        Why do you check

        if(isset($_POST['submit']))

        ? Obviously that is false and you've trapped the problem and displayed the error message you wrote.

        CQ de W5ALT

        Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

        G Offline
        G Offline
        Gagan 20
        wrote on last edited by
        #3

        ok, then tell me what should I write to send e-mail because I am new to PHP. Help me. Thanks. Gagan

        D 1 Reply Last reply
        0
        • G Gagan 20

          ok, then tell me what should I write to send e-mail because I am new to PHP. Help me. Thanks. Gagan

          D Offline
          D Offline
          Dr Walt Fair PE
          wrote on last edited by
          #4

          Your email sending part looks fine. I use

          mail($to, $subject, $contents, $from_header);

          with the $from_header, although that might be optional. But that's not the problem you are seeing -- your code isn't even getting there. Looking at your PHP code, the first thing executed is

          if(isset($_POST['submit']))

          Since you get the message you showed, obviously that is being evaluated as false, so the else part is executed showing the message. So my question to you is: Why are you checking to see if the 'submit' POST variable is set? That's where your code is having problems -- before it ever gets to sending the email. My suggestion is to take the if/else out and run the code to send the email. That should work if email is allowed on your server. If it works, then you can go back and check for whatever you want to check for with the if statement. See the following links for examples: http://www.webcheatsheet.com/php/send_email_text_html_attachment.php[^] http://php.about.com/od/phpapplications/ss/form_mail.htm[^]

          CQ de W5ALT

          Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

          G 1 Reply Last reply
          0
          • D Dr Walt Fair PE

            Your email sending part looks fine. I use

            mail($to, $subject, $contents, $from_header);

            with the $from_header, although that might be optional. But that's not the problem you are seeing -- your code isn't even getting there. Looking at your PHP code, the first thing executed is

            if(isset($_POST['submit']))

            Since you get the message you showed, obviously that is being evaluated as false, so the else part is executed showing the message. So my question to you is: Why are you checking to see if the 'submit' POST variable is set? That's where your code is having problems -- before it ever gets to sending the email. My suggestion is to take the if/else out and run the code to send the email. That should work if email is allowed on your server. If it works, then you can go back and check for whatever you want to check for with the if statement. See the following links for examples: http://www.webcheatsheet.com/php/send_email_text_html_attachment.php[^] http://php.about.com/od/phpapplications/ss/form_mail.htm[^]

            CQ de W5ALT

            Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

            G Offline
            G Offline
            Gagan 20
            wrote on last edited by
            #5

            Thanks for your help. I just removed the line if(isset($_POST['submit'])) and it worked. Thanks :)

            D 1 Reply Last reply
            0
            • G Gagan 20

              Thanks for your help. I just removed the line if(isset($_POST['submit'])) and it worked. Thanks :)

              D Offline
              D Offline
              Dr Walt Fair PE
              wrote on last edited by
              #6

              Glad to hear it works! I'd also remove the rest of the if/else braces. To check for errors you probably should wrap the mail command in an if, too. See the links I posted before for examples.

              CQ de W5ALT

              Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

              1 Reply Last reply
              0
              • G Gagan 20

                Hi all. I am new to PHP and trying to learn it.I have created a web page and defined items as below :

                <form method="POST" action="send.php">
                <font color="green"> Full Name : </font>
                <input type="text" name="name" size="20">

                  <font color="green"> Gotra(Clan) : </font>
                  <input type="text" name="gotra" size="20">
                
                  <font color="green"> Father's Name : </font>
                  <input type="text" name="fname" size="20">
                
                  <font color="green">Details of Prasad to be Offered : </font>
                

                (eg.: name of temple, quantity of prasad, specific date & any other requirements)
                <textarea rows="5" name="prasad" cols="40" ></textarea>

                  <font color="green"> Any Wish to God  : </font>
                  <textarea rows="5" name="wish" cols="40" ></textarea>
                
                  <font color="green"> Postal Address : </font>
                  <textarea rows="5" name="address" cols="40" ></textarea>
                
                  <font color="green"> Phone no.  : </font>
                  <input type="text" name="phone" size="20">
                
                  <font color="green"> Preferred Time of Contact : </font>
                  <input type="text" name="time" size="20">
                
                  <font color="green"> Email address : </font> 
                  <input type="text" name="email" size="20">
                
                <br>      
                 <input name="Submit" type="submit" class="input" value="Send">
                     <input name="Submit2" type="reset" class="input" value="Reset">
                    </br>         
                 </form>
                

                and the send.php has following block of code :

                <?php
                if(isset($_POST['submit'])) {
                $to = "gagan.u20@gmail.com";
                $subject = "E-Prasad Details";
                $name_field = $_POST['name'];
                $gotra_field=$_POST['gotra'];
                $fname_field = $_POST['fname'];
                $prasad=$_POST['prasad'];
                $wish=$_POST['wish'];
                $address=$_POST['address'];
                $phone_field=$_POST['phone'];
                $time_field=$_POST['time'];
                $email_field=$_POST['email'];

                $body = "From: $name_field\n Gotra: $gotra_field\n Father's name: $fname_field\n Details of prasad to be offered : $prasad\n Any wish to God: $wish\n Postal address : $address\n Phone no. : $phone_field\n Preferred time of contact : $time_field\n E-mail address : $email_field";

                echo "Data has been submitted!";
                mail($to, $subject, $body);
                } else {
                echo "An error occurred! Please try again.";
                }
                ?>

                Now the problem is, when I fill the form and cl

                A Offline
                A Offline
                adslccn
                wrote on last edited by
                #7

                here: <input name="Submit" type="submit" class="input" value="Send"> and here : if(isset($_POST['submit'])) so if(isset($_POST['submit'])) =>if(isset($_POST['Submit'])) This is a common problem

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups