Question:
how do i make a submit button in a php form send an email out?
anonymous
2014-02-11 11:20:12 UTC
I am creating a form for a website and the submit button must send an email out to the admin. people have told me to use the
method. how would i implement that into the code i have right now?





























Six answers:
anonymous
2014-02-11 11:44:31 UTC
If you want to use PHP which is Server Based just do on the action page of the action="/admin/events"

And add a hidden value... or not use one already set...

and do:



if (isSet($_POST['start_time'])){

// sorry Nik: {

$subject = "Messages Recieved";



$message_body = "You have received messages on your website. \n";



$headers =

"From: email address" . "\r\n" .

"Reply-To: email address" . "\r\n" .

'X-Mailer: PHP/' . phpversion();



$mail_response = mail("send to email address" , $subject, $message_body, $headers);



}



why not just do a onClick on the submit button and run a javascript mail to function:



function sendEml()

{

window.open('mailto:test@example.com?subject=subject&body=body');

}



or use JQuery:



$( "#button" ).on( "click", function(event) {

$(this).attr('href', 'mailto:me@domain.com?subject=hello');

});
?
2014-02-11 12:11:37 UTC
Only Nik sorta kinda got it right.



You cannot send an email with HTML or JavaScript (or jQuery, which is just JavaScript). The mailto: business will fail for 80% to 90% of people, namely those who don't have a default email application (like Mail, Thunderbird, Outlook) set up and in use.



What you need to do is make the server that is hosting your website send out the email. You can do this if the server supports PHP or another server-side scripting language.

In order for this to work, the form's action attribute has to link to a PHP document, which in turn will read the $_POST data entered into the form, compose an email using that data and send it along.



Here's a basic HowTo: http://www.phpeasystep.com/phptu/8.html
anonymous
2016-03-10 05:08:01 UTC
I very much want to help you clean up that form, it is a mess... separate your content from presentation, use external stylesheets. That page is so over bloated, and the form is just an utter confusing mess. Sorry to be so blunt, but it is constructive criticism. The worst thing you could have done is made the layout table-based instead of div based. Do you have a formmail script that will send the info to the correct place? Hit me up and I can help you out if you got time.
anonymous
2014-02-11 14:49:57 UTC
You will need to use php in your action file to read the posted fields, and then mail it to the admin. Check out php mail tutorials. Another much easier/faster option is to use a website builder that has a forms builder built-in, where you can customize it too. A good one for that is ultimatewb.
?
2014-02-11 11:27:34 UTC
You simply replace the form action, "/admin/events" with

"mailto:" where is

the email address of your admin.



But I don't think the form fields would transfer over this way.
Nik
2014-02-11 11:28:21 UTC
Don't use mailto its flawed. It assumes the visitor to your website has a mailing application installed on their computer and opens it.



You can mail directly with PHP but it must be on an online server with a mail system set up.



$subject = "Messages Recieved";



$message_body = "You have received messages on your website. \n";



$headers =

"From: email address" . "\r\n" .

"Reply-To: email address" . "\r\n" .

'X-Mailer: PHP/' . phpversion();



$mail_response = mail("send to email address" , $subject, $message_body, $headers);


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...