July 8, 201115 yr Here's a silly question for you guys ... In an HTML form, when you specify that the data should got to an email address e.g. action="mailto:someone@whatever.org" how does the email actually get there? Surely it's not enough to just write this, it has to be connected to an email account at the sending end, surely? I expect this shows a basic lack of understanding of how it all works, but I'm keen to be enlightened!
July 8, 201115 yr The mailto function opens the user's email client, like Outlook, and fills in the email with the data ready to send. So this method doesn't work if the user is in an internet cafe or at a friend's house where there isn't an email client. It's better to use a PHP web form where the data is sent to a PHP process code and the host's server sends it directly.
July 9, 201115 yr Author Thanks for the reply. OK, I think I get it. You're saying that even when it's in a form, mailto works the same as when you use it on the page, I can see how that wouldn't be ideal! I'll have a think about the PHP bit and come back when I get it ...
July 9, 201115 yr Thanks for the reply. OK, I think I get it. You're saying that even when it's in a form, mailto works the same as when you use it on the page, I can see how that wouldn't be ideal! I'll have a think about the PHP bit and come back when I get it ... Using mailto is pretty unsecure, but heres an example of sending form details using phps mail function $to = "admin@mysite.com";//Where the email will go $subject = "My website";//Subject of email $name = (isset($_POST['name'])) ? htmlentities($_POST['name'],ENT_QUOTES,'UTF-8') : ''; $email = (isset($_POST['email'])) ? htmlentities($_POST['email'],ENT_QUOTES,'UTF-8') : ''; if($name && $email){ $message = ""; $headers = ""; $message .=" you have a new email from your website<br /><br /> Name:$name<br /><br /> E-mail:$email "; /**Set headers**/ $headers .= "From:$name <$to>\r\n"; $headers .= "Content-Type:text/html; charset=utf-8\r\n"; if(@mail($to,$subject,$message,$headers)){ print 'Your message has been sent!'; }else{ print 'We have failed sending your message!'; //exit script exit; } } You will also wanna filter the name to contain just letters and numbers to prevent header injections which you can easily do like this $name = preg_replace("^[A-Za-z0-9]","",$name); Edited July 9, 201115 yr by webdesigner93
Create an account or sign in to comment