1

I want to send mail through the php and html code. I have made form in html. Here is my code

<form name="contactform" method="post" action="send_form_email.php"> 
     <table width="450px">
          <tr>   
               <td valign="top">
                    <label for="first_name">First Name *</label>
                </td>
                 <td valign="top">
                    <input  type="text" name="first_name" maxlength="50" size="30">
                </td>
            </tr>
            <tr>
                <td valign="top"">
                    <label for="last_name">Last Name *</label>
                </td>
                <td valign="top">
                    <input  type="text" name="last_name" maxlength="50" size="30">
                </td>
            </tr>       
            <tr>
                <td valign="top">
                    <label for="email">Email Address *</label>
                </td>
                <td valign="top">
                    <input  type="text" name="email" maxlength="80" size="30">
                </td>
            </tr>
            <tr>
                <td valign="top">
                    <label for="telephone">Telephone Number</label>
                </td>
                <td valign="top">
                    <input  type="text" name="telephone" maxlength="30" size="30">   
                </td>
            </tr>
            <tr>
                <td valign="top">
                    <label for="comments">Comments *</label>
                </td>    
                <td valign="top">
                    <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align:center">
                    <input type="submit" value="Submit">Email Form
                </td>
            </tr>
        </table>
 </form>

and after that I have code in php file from that email can be send. Here is my code

<?php
    $name ="$first_name";
    $lastname ="$last_name";
    $telephone ="$telephone";
    $emailid ="$email";
    $comment ="$comments";

    //from
    $header ="from : $name <$emailid>";
    $to ="sonikaran006@gmail.com";

    $send_form_email =mail($to, $name, $lastname, $emailid, $telephone, $comment);

    if($send_form_email)
    {
    echo "We have received your information";
    }
    else
    {
    echo "Error";
    }   
?>

But when I run the form at that time it shows error and print in notepad like this

";$to ="sonikaran006@gmail.com"; $send_form_email =mail($to, $name, $lastname, $emailid, $telephone, $comment); if($send_form_email) { echo "We have received your information"; } else { echo "Error"; } ?>

So, I can't understand what's going wrong in my code. Please help me to solve this error. This is html form named "contactform"

This is error coming in php form named send_form_email.com/LidLK.png

karan
  • 482
  • 1
  • 8
  • 30
  • 2
    Looks like the php is not proceed –  Dec 06 '16 at 07:41
  • may i know how. Because I am new in Php. So it is too difficult for me to that how proceed php. – karan Dec 06 '16 at 07:44
  • 1
    Your running this on a Web server with php installed? –  Dec 06 '16 at 07:45
  • i think in the textarea tag you have to set the form (form="contactform"). Also, do you get the post values from i.e. $_POST['first_name'] or do you just assume there is a variable called $first_name ? – kscherrer Dec 06 '16 at 07:46
  • nope. I am just running in notepad++. So when html form button click it goes to the php page and then after php page is perform. @Dagon – karan Dec 06 '16 at 07:49
  • Well you need to run this on a Web server with php –  Dec 06 '16 at 07:50
  • can you show the screen shot of the redirection of the form – Beginner Dec 06 '16 at 07:50

0 Answers0