0

After finding out that php need to be run through a server and not as a normal .html file, I need to send an email to the "person" to make an appointment.

Here is my code:

                <?php
                    echo "<form method='post' action='mailform.php'>
                    Email: <input name='email' type='text'><br>
                    Subject: <input name='subject' type='text'><br>
                    Message:<br>
                    <textarea name='message' rows='15' cols='40'>
                    </textarea><br>
                    <input type='submit'>
                    </form>";

                    $email = $_REQUEST['email'] ;
                    $subject = $_REQUEST['subject'] ;
                    $message = $_REQUEST['message'] ;
                    if(mail($email, $subject, $message, "From:" . $email))
                    {
                        printf("Email sent.");
                    }
                ?>

But it doesnt send the email. This code is imbedded inside a .html file and I execute it by http://localhost/email.php

5
Contributors
8
Replies
44
Views
4 Years
Discussion Span
Last Post by MasterHacker110
0

No good linking to a file on localhost, we're not connected to your computer!
Unless you are connected to the internet, and have set the SMTP server address in php.ini file, nothing will be sent from 'localhost'

0

localhost does not have an smtp server, mail() does not work without an smtp server
html filoes do not process php commands, unless you have modified the configuration "addhandler serverparsed"
the php helpscreens at php.net are very good, and include
EDIT: Correct
code samples, would be probably a good idea to view the mail() help page

Edited by almostbob

0

Yep, as others have said you need to be running some form of mail server. The simplest you could probably do is to run a relay email server and download something like sSMTP.

A relay email server is essentially one which rides on the back of a proper email server. It shall connect to a main server such as one from your ISP, GMail, Yahoo etc. and then send it from there. It is easier and less demanding than running a full blown email server.

-1

read the mail logs, you will find info there:
tail -f /var/log/mail.err or tail -f /var/log/mail.log

if you are on a shared hosting, it should work by default. if you have home/VPS/Dedicated server/pc try setting qualified domain name in /etc/hosts:

[ipaddress] [longname] [shortname]

127.0.0.1 yourdomainname.com yourdomain

more info: http://newexception.com/unable-to-qualify-my-own-domain-name

0

@dorco, read the prior posts, you will learn as well, there is no smtp server on a wamp localhost
no mail server to send mail, => there are no server logs
you cannot the same answer applies
ignorance is not bliss
wrong answers dont help
whatever dont make wrong, right.

Edited by almostbob

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.