Send email while submitting form

Sorry if the title is a bit vague. I want to say that I have the code as shown below:

<?php /* ...generate $to, $subject, $msg, $from variables here */ if(isset($_POST['ccbutton_pressed'])) { if(mail($to, $subject, $msg, $from)){ echo 'Order Sent'; }else{ echo 'Order Sending Error'; } }?> <form method='post' action='SOME_URL_TO_POST_TO' > <!-- some visible input types --> First name: <input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br> <!-- some hidden input types --> <input type='hidden' name='hiddenfield1' value='1' /> <input type='hidden' name='hiddenfield2' value='2' /> <input type='submit' value='Submit' /> <input type='hidden' name='ccbutton_pressed' value='1'> </form> 

Is there a way to send an email after sending? Noting the following points below:

  • prefers php because it is a server part, and information is kept confidential.
  • The 'action' attribute must be published and cannot be changed (I need it to go to another page / form)
  • Open to use Javascript, while the contents of the message may be hidden in some way (but doubtful)
  • I already tried to place the php block that started when the hidden field was set in this form, but in this case it does not work.

Update: Changed the code block to explain more information. This is also not a duplicate, because in Send an email with PHP from the html form when submitting with the same script , the "action" remains empty, while I need my message somewhere.

I would also add that I checked the above article and it does not work for me.

+4
source share
2 answers
 <?php if(isset($_POST['submit'])){ $fname=$_POST['fname']; $lname=$_POST['lname']; $toemail=" abc@gmail.com "; $subject="Sending Mail"; $message="Firstname:".$fname."<br/>"; $message.="Lastname:".$lname; $headers = "From: webmaster@example.com " . "\r\n" . "CC: somebodyelse@example.com "; //sending simple mail mail($toemail, $subject, $message, $header); } ?> <form method='post' action='' > <!-- some visible input types --> First name: <input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br> <!-- some hidden input types --> <input type='hidden' name='hiddenfield1' value='1' /> <input type='hidden' name='hiddenfield2' value='2' /> <input type='submit' value='Submit' id="submit" name="submit" /> </form> 

Greetings

+1
source

All Articles