Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear friends,
Any one tell me how to send mail from html using php send mail code. i use above urls. it didn't send mail. but it display php code on browser

What I have tried:

https://www.quackit.com/html/codes/html_form_to_email.cfm
http://form.guide/contact-form/php-email-contact-form.html
Posted
Updated 24-Jan-18 17:29pm

Quote:
it didn't send mail. but it display php code on browser
It seems that your web server is not supporting PHP scripts. You have to ensure that PHP is installed on the server, configured (including SMTP relevant parts when using PHP: mail - Manual[^]), and that the web server is configured to execute PHP scripts.

If you have dircet access to the web server, read the documentation of the web server software about PHP support.

If you don't have access to the web server configuration, ask your hoster. If you have limited access (e.g. via an web interface), read the documentation provided by your hoster or ask him. Note that some hosters have pre-configured PHP but might restrict the execution to specific paths (again, read the documentation or ask your hoster).
 
Share this answer
 
Comments
Vivek.anand34 23-Jan-18 7:29am    
php is installed. wamp server is there in system.
Jochen Arndt 23-Jan-18 7:41am    
Then check your Apache configuration regarding PHP. The Apache access and error log files might also have some information.
Vivek.anand34 23-Jan-18 22:45pm    
sorry am new to php.. how to check apache config. What information need to check in apache
Jochen Arndt 24-Jan-18 2:49am    
Apache must be configured to execute PHP scripts. Because you are using WAMP, that should be already the case (I have never used that but the descriptions assumes it). Typical Apache configurations do not allow script execution on all pathes. They might be restricted to a specific (CGI) directory. Then you have to save your script in that directory and call with that path.

There are tutorials for WAMP. I suggest to read one and try the provided PHP examples (it is better to begin with a simple script to just get PHP scripts executed).
You can try this if you are generating email form contact form..

<?php
    if(isset($_POST['name']))
    {
    $name = trim($_POST["name"]);
    $email = trim($_POST["email"]);
    $subject = trim($_POST["subject"]);
    $message = trim($_POST["message"]);
    $answerbox = trim($_POST["answerbox"]);
    if(strlen($name)<2) {
        print "<p>Please type your name.</p>";
    }else if(strlen($subject)<2) {
        print "<p>Please type a subject.</p>";
    }else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        print  "<p>Please type a valid email address.</p>";
    }else if(strlen($message)<10) {
        print "<p>Please type your message.</p>";
    }else if($answerbox != 15) {
        print "<p>Please answer the math question.</p>";
    }else{
                $headers =  'From: '.$email. "\r\n" .
                            'Reply-To: '.$email . "\r\n" .
                            'X-Mailer: PHP/' . phpversion();
        mail('me@mymail.me',$subject,$message,$headers);
        print "mail succesuffully sent";
    }

}
    ?>

        <form name="contact" action="form2.php" method="post">
            <input type="hidden" name="submitted" value="true"/>
            <label for="YourName">Your Name:</label>
            <input type="text" name="name" class="required" />

            <label for="YourEmail">Your Email:</label>
            <input type="text" name="email" class="required"/>

            <label for="Subject">Subject:</label>
            <input type="text" name="subject" class="required"  />

            <label for="YourMessage">Your Message:</label>
            <textarea  name="message" class="required"></textarea>
            <p class="c3">10 + 5 =<input type="text" name="answerbox" id="answerbox" /></p>

        <fieldset>
            <input type="submit" name="submit" id="submit" value="Send" class="required"/>
            <input type="reset" id="reset" value="Reset"/>      
        </fieldset>

    </form>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900