php send mail help

Soldato
Joined
11 Jul 2004
Posts
16,147
Location
Neptune
I'm trying to recreate a form that will send an email with the content that the user gives in the various fields. I've never done this before and need help.

I've recreated a form in Dreamweaver from the customer's previous site, but i need to code the submit button to send it over to them via email.

The send button's value is currently: <input name="Submit" type="submit" value="Send Details"> but on testing it is asking for a send.php file (which i don't have).

Thank you
 
Last edited:
Look at the beginning of the form code, it will look like:

<form action="send.php" method="post">

When you click submit the server is expecting a send.php file to be present which will handle the request.
 
Ok, it has the following:

<form name="form1" method="post" action="valuation_send.php">

Where would the php script be stored on the site? I don't have their FTP details yet so can't log on and find it that way. Could it be anywhere or only in a certain place (eg local to the page you're on)?

EDIT If i put in the website then the 'valuation_send.php' (eg www.mysite.com/valuation_send.php) it immediately forwards to a thank you page so i presume that's the location of the php code, but i can't grab it using Flashget or anything like that.
 
The "action" attribute expects a path... so if you only have the file name it is safe to assume the valuation_send.php is local to the contact/email page.

Once you have the FTP details you should be able to see all the .php files the old site uses [and can probably reuse some of it - if that is allowed.].
 
Javascript is client-side... I didn't know you could use it to send emails.

That aside, PHP is better. For a start you're stuck if the user has Javascript disabled. PHP is server-side, so it doesn't matter what configuration the client has.
 
how does that work? :confused:

you need an smtp server/server side scripting language to send mail via a form. :)

A java "script" not javascript :)

I'm assuming he uses javamail? if he is using javascript I'm fairly sure that behind closed doors it's hitting a perl or server side script (well it has to be lol).
 
No, it is a java script, well applet. It basically opens the site visitors email client, puts whatever data they put on the webpage form in an email and sends it.
 
Code:
<a href="mailto:[email protected]?subject=THESUBJECT&[email protected]&[email protected]&body=BODY">EMAIL</a>

So it's basically just a link, constructed with js.

Very naughty though, basically what if....

A) web based email client (googlemail, aol, yahoo, hotmail etc...)

B) Public internet

C) work pc

D) Not your own pc (you want a reply address right?)

E) Hello spammer bots! ;)
 
Last edited:
Try this... Although I have kinda pseudo coded it, so might need some tweaking....


sendEmail.html
Code:
<form method="get" action="sendMail.php">
    <input type="text" name="replyAddy" size="95">
    <textarea name="body" rows="2" cols="20"></textarea>
    <INPUT TYPE=SUBMIT VALUE="submit">
</form>

sendMail.php
PHP:
<?php
if((isset($_GET['replyAddy']) && isset($_GET['body'])) || !validEmail($_GET['replyAddy']) || naughtyBody($_GET['body'])) 
{
	$to      = '[email protected]';
	$subject = 'WEB ENQUIRY';
	$message = $_GET['body']);
	$headers = 'From: '.$_GET['replyAddy']. "\r\n" .
	    'Reply-To: '.$_GET['replyAddy']. "\r\n" .
	    'X-Mailer: PHP/' . phpversion();

	mail($to, $subject, $message, $headers);
}
?>
 
Last edited:
Only thing I would do differently is changing GET to POST. Other than that looks good.

You may also want to include some validation.
 
Only thing I would do differently is changing GET to POST. Other than that looks good.

You may also want to include some validation.

Good shout on the get, that was me being a bit lazy!

Validation on email and body obv I haven't written, that can be fun for the OP to do ;)
 
Back
Top Bottom