Reputation: 644
Sorry if the title is a bit vague. What I mean to say is I have a code like 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 some way I can send an email upon submission? While taking notes on the following points below:
Update: Changed code block to explain more information. This is also not a duplicate because in Send email with PHP from html form on submit with the same script, the 'action' is left blank while I need mine to post to somewhere.
I'd also like to add that I have checked the above article and it doesn't work for me.
Upvotes: 4
Views: 464
Reputation: 533
<?php
if(isset($_POST['submit'])){
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$toemail="[email protected]";
$subject="Sending Mail";
$message="Firstname:".$fname."<br/>";
$message.="Lastname:".$lname;
$headers = "From: [email protected]" . "\r\n" .
"CC: [email protected]";
//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>
Cheers
Upvotes: 1
Reputation: 61
You can probably look at these links to help you.
Send email with PHP from html form on submit with the same script
How to create an email form that can send email using html
Thanks
Upvotes: 0