I want to put a form on my website which will work on any browser and preferably doesn't make the user have to see the e-mail and have to click send.

If this isn't possible I would just like a form for my website which will work in internet explorer and will either e-mail the info to me or enter it straight into a javascript file on my site.

Hope you can help.
:lol: Martin :lol:

Dani AI

Generated

A reliable, cross‑browser way to avoid opening the visitor's mail client is to submit the form to server‑side code that sends (or stores) the message. already pointed out that this must be done server‑side; the notes below expand that into a minimal workflow, a safe starter script, and troubleshooting tips for someone new to server programming like . 's .NET tutorial is an alternate route for those on Windows/.NET hosting.

A minimal HTML form (method POST) that posts to a server script:

<form action="send.php" method="post">
  <input name="name" placeholder="Name" />
  <input name="email" type="email" placeholder="Email" />
  <textarea name="message" placeholder="Message"></textarea>
  <button type="submit">Send</button>
</form>

A very small PHP processor (illustrative; adjust and harden before production):

<?php
$name    = trim(filter_input(INPUT_POST,'name',FILTER_SANITIZE_STRING));
$email   = trim(filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL));
$message = trim(filter_input(INPUT_POST,'message',FILTER_SANITIZE_STRING));

if (!$email) exit; // basic validation

// prevent header injection
if (preg_match("/[\r\n]/", $email.$name)) exit;

$to = 'owner@domain.com';
$subject = "Contact from $name";
$body = "Name: $name\nEmail: $email\n\n$message";
$headers = "From: no-reply@domain.com\r\nReply-To: $email\r\n";

mail($to, $subject, $body, $headers);
?>

Key cautions and next steps: always validate and sanitize input, block header injection, add CSRF protection and a simple CAPTCHA to reduce spam, and never write raw user input to a public JS file. If built‑in mail() fails or deliverability is poor, send via authenticated SMTP using a library (e.g., PHPMailer) and a real SMTP account. For quick, no‑server options, hosted form services or a Google Form can collect messages without exposing the visitor's mail client. For step‑by‑step help setting up a local PHP test server (XAMPP/WAMP) or adapting the above, continue the discussion in the PHP forum as suggested.

Recommended Answers

All 9 Replies

Form processing and email generation are server-side tasks. You'll need to ask this question in the forum for whichever server-side language you use (PHP, ASP, ASP.NET...).

I'm completely new to any programming languages except for javascript (I know a bit about) and HTML (I know much more about).
How do I insert them into a web page?

:?: Martin :?:

Insert them? "them" what?

A server-side language isn't inserted onto a web page. It outputs the web page. Seriously, if you're going to be a web developer, you'll need to learn the server side of things. Start at www.php.net, is my advice.

Sorry - I meant how do I insert one of the programming cades into HTML (or can't I)?

Martin

I'm not familiar with the term "cades".

A server-side language works in conjunction with the Web Server software itself (such as IIS or Apache), to generate web pages.

When the user makes a request to a page like "mypage.php", the Web Server runs the program contained in the php file. The php file can perform a variety of tasks, such as looking up information from a database, performing calculations, etc.

Then, it outputs a Reponse. That Response contains all the HTML, CSS, and JavaScript that the client is supposed to see. The Web Server sends that to the browser.

In your case, you could have a static standard Web Page, with a form, which submits to a php program. One of the things a server-side program can do is process the form results, and generate and send emails.

If none of this answers your question, then you need to ask better questions! :)

Sorry, Sorry, Sorry.
I mis-typed it - I meant CODES.

How do I get the form to be prosessed and e-mailed by .php?
(Should I be in a different forum?)


:o Sorry for all the confusion :o
Martin

Yes, you should be in the PHP forum.

The basics: set the form action tag to point to a PHP program.

When the user submits, the PHP program runs.

The PHP program calls its built-in email function.

Start by visiting www.php.net.

Then for more details, post in the PHP forum here on Daniweb.

Thanks.

:lol:Martin:lol:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.