How do I send email via PHP from within an HTML file? -


my website html5. consequently, files .html. have contact.html file use send message from, using php. don't have experience php (so if recommend better alternative, non-.net way of sending email, please let me know).

my initial thought include php code inside html file (whether or not possible or recommended, don't know). i've done once before, , believe remember having form tag somewhere in attributes specified .php file used send email.

something <form someattribute="sendmail.php"> ... </form>.

question: given think should (above), best approach (specifying php file inside form tag), or recommend better way send email raw .html file?

you cannot html. if stick php solution, try

<?php     if(isset($_post['send'])) //check submit button pressed     {         //get variables post array. remember specified post method         $to = $_post['to'];         $subject = $_post['subject'];         $message = $_post['message'];          //set headers         $headers = 'from: webmaster@example.com' . "\r\n" .                     'reply-to: webmaster@example.com' . "\r\n" .                     'x-mailer: php/' . phpversion();          //send email , save result         $result = mail($to, $subject, $message, $headers);           //was sent?         if($result)         {             echo "successfuly sent email";         }         else         {             echo "an error has occured";         }     } ?> <hr> <form method="post">     to: <input type="text" name="to"> <br>     subject: <input type="text" name="subject"> <br>     text: <textarea name="message"></textarea><br>     <input type="submit" value="send" name="send"> </form> 

you not need specify form points because same file. otherwise be

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

altough have specify method post, otherwise data sent through default

php has mail function used send email http://php.net/manual/en/function.mail.php

returns true if mail accepted delivery, false otherwise.

we check if email sent or not , print corresponding message. then, regardless of result, print out message form.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -