Send Email Based On Selection (with File Upload)
I'm trying to create a page for my website, where students have to select 3 or less out of about 10 choices(multiple selection). They also need to upload a file below this. When th
Solution 1:
I dont have a sample code to give you, but roughly, it would be something like this:
<html>
<head>
<script type="text/javascript">
function my_js_submit()
{
// check the email input fields that you care about.
if(document.getElementById("email1").value != "" &&
document.getElementById("email2").value != "" &&
document.getElementById("email3").value != "")
{
document.forms["my_form"].submit(); //this will call the php where you do
//emailing
}
else
{
alert("Please fill in all three emails");
}
}
</script>
</head>
<body>
<!-- submit_handler.php is where you send emails -->
<form id="my_form: method="post" action="submit_handler.php">
<input type="text" id="email1" />
<input type="text" id="email2" />
<input type="text" id="email3" />
<input type="text" id="message" />
<button onclick="my_js_submit();"> Submit </button>
</form>
</body>
</html>
PHP most basic code (name this file submit_handler.php):
<?php
$to = $_POST['email1'] . "; " . $_POST['email2'] . "; " . $_POST['email3'];
$subject = "Email subject";
$message = $_POST['message'];
$from = "From: your_email@yourDomain.com";
mail($to,$subject,$message,$from); // The Mail function at work
// Redirect your user to a page of your choice
header("Location: http://www.some_page.com");
?>
Post a Comment for "Send Email Based On Selection (with File Upload)"