![]() |
send a mail from your website
here is a simple form that will send a mail to you from a page on your web site.
First a form using some html5 validation that will show errors when you submit. I have made some fields required, email and url will be validated the action is set to send.php where the mail sending script will reside. Code:
<!DOCTYPE HTML> there is a var named $th_url that is the url redirect that the visitor will be directed to after a successful submission, with no errors. send.php Code:
<?php i intend to extend this with some more examples as anti spam , time permitting |
Ed - just trying this out but feel i'm missing something really obvious...
tried it locally in mamp and it allegedly sent, got to the thank you page but it simply doesn't arrive at my email. uploaded it to http://gekkoweb.com/hl2015/form.html and still no joy. i removed the web site field from the form and the send.php i used my email address and plugged it in here: if (!$errors) { $mail_to = 'gekkoweb@gmail.com'; $subject = 'New Mail from ' . $_POST['email']; $message = 'From: ' . $_POST['name'] . "\n"; $message .= 'Email from: ' . $_POST['email'] . "\n"; $message .= "Message:\n" . $_POST['Message'] . "\n\n"; mail($to, $subject, $message); I suspect that this is where i'm going wrong "the action is set to send.php where the mail sending script will reside" - so my cgi bin or ??? this is really useful because for a while now i've been looking for a simple form like this but there's so much crud on the net finding something decent and made in the last 10 years :) also i was a bit embarassed to ask before... ;) |
id better test it, ime prone to rushinhg :) usingh a local setup you need a real stmp server . i use a tool called test sender from http://www.toolheap.com/test-mail-server-tool/. it saves the email a s a file . not sure of a apple or linux version though.
As for path the setup is for the form p[age and mailsending form to be in the same directory, another opyion is toset the action to itself action=" " and paste the php code at the page starht before the html |
yup its me
$mail_to = 'me@somewhere.com'; should read $to = 'me@somewhere.com'; |
I just edited it and tested live and all is ok. Sorry about that :).and Dave feel free to emaiol me if you are embarassed though there is no need to be :)
|
yep all works now, thanks.
embarassed because i've been doing this a long time and i should know how to do it by now, though i've never learnt php... one more quick qestion for my benefit and anyone else using this thread: where you have // modify to page redirect after mail succsessfully sent after taking the user to the thankyou page, could you detail the redirect bit for us? or is it a better to just provide the user with a normal link back to the homepage? look froward to the antispam ;) |
i would say that depends. f'rinstance, on a job site i redirect back to the new jobs on others a thank you page with various link options, or sometimes the index page
|
i will post a version with html and an anti spam 'honey trap' tomorrow
|
ok this adds a couple of things to include a honey-pot or honey trap.
in essence, it is a form that should not get filled in. if your site is being spammed by a bot it will with luck fill in the field. the receiving php script will not allow the mail then to be sent. it is pretty effective , although not foolproof but then i have not found any way that is 100% effective, even captchas which can be used as well as a honey trap. ok the form adds a field, in this case i have called it myrealname . I have also added a css class that will not allow the input to be shown. This can be removed or commented out while testing if you want .robotic { display: none; } so the code Code:
Code:
<?php |
that's great ed, thanks loads. will have a look at that later today ;)
|
All times are GMT. The time now is 11:02 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com