working when you click "send" email to come forward with a box which read "thanks for the information." and after the box slideup again after 1min.
when I click on "send" and then it just down but the slider is not up in some manner whatsoever.
<div class="kontakt_box">
<h3>Kontakt Mads Ørnfeldt Andersen</h3>
<p>Kom i kontakt med Mads Ørnfeldt Andersen</p>
<form action="#" method="post" name="kontakt_box">
<label>Navn<br /><input type="text" name="navn" required title="Angive et Navn" class="new" placeholder="Navn"></label><br />
<label>Efternavn<br /><input type="text" required title="Angive et efternavn" name="efternavn" class="new" placeholder="Efternavn"></label><br />
<label>Email<br /><input type="email" required title="Angive en email!" name="email" class="new" placeholder="Email"></label><br />
<label>Tekst<br /><textarea name="tekst" cols="35" rows="10" class="new" placeholder="Tekst til email"></textarea></label><br />
<label><input type="submit" name="send" value="Send" class="new send_email"></label>
</form>
<?php
if(isset($_POST["send"]))
{
$email_afsender = $mebe->email_afsender();
}
if($_SESSION["email_sendt"] == true)
{
echo "<div class=\"tak_email\">Tak</div>";
}
?>
</div>
<script>
$('.send_email').click(function() {
$('.tak_email').slideUp('slow', function() {
// Animation complete.
});
});
</script>
here are im my function:
function email_afsender()
{
$_SESSION["email_sendt"] = true;
$fra = $_POST["navn"] . " " . $_POST["efternavn"] . "<" . $_POST["email"] . ">";
$til = "jp#absb.dk";
$emne = "Kontakt blabla.dk - " . $_POST["navn"] . " " . $_POST["efternavn"];
$besked = $_POST["tekst"];
//headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: " . $fra . "\r\n";
mail($til, $emne, $besked, $headers);
$TargetPage = "/kontakt/";
header('Location: ' . $TargetPage);
}
Your code is not valid. You did not specify the action file in your form and you are going to submit it??
Related
I am creating an assessment which will send results to the teacher and the student. I can't get the results to be sent to the student, only the teacher. Here is what I have below:
index.php
<form id="form1" name="form1" method="post" action="results.php" onsubmit="return validateForm() ;">
<label>First Name
<input type="text" name="fname" id="fname" tabindex="1" />
</label>
<label>Last Name
<input type="text" name="lname" id="lname" tabindex="2" />
</label>
<label>Title
<input type="text" name="title" id="title" tabindex="3" />
</label>
<br />
<br />
<hr />
<?php
$quiz = new Quiz( $questions );
echo $quiz->renderQuiz();
?>
<br/>
<label>Enter the email addresses you would like to receive your results, separated by semicolons.</label><br/>
<input type="text" name="email_to" tabindex="4" size="80" />
<input name="Submit" type="submit" value="Submit" />
</form>
results.php
$force_email = array( "test#test.com", test1#test.com);
function create_email_string( $force_email, $user_input )
{
if (!empty( $user_input ))
{
$email_string = $user_input . "; " . implode("; " , $force_email);
}
else
{
$email_string = implode("; " , $force_email);
}
return $email_string;
}
$ip = $_SERVER['REMOTE_ADDR']; // employee's Ip address
$time = date("d/m/y : H:i:s", time()); // current timestamp
$email_string = create_email_string( $force_email, $_POST['email_to'] );
$questions_correct = array();
$results_data_page = $_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
$file_start = (strrpos($results_data_page, "/")+1);
$results_data_page = substr_replace($results_data_page, "results_data_page.php?test_name=" . rawurlencode($test_name), $file_start);
$variables = array();
$variables['fname'] = $_POST['fname'];
$variables['lname'] = $_POST['lname'];
$variables['test_name'] = $test_name;
$variables['score'] = $score;
$variables['table'] = create_results_table( $questions, $questions_correct );
$variables['results_data_page'] = $results_data_page;
$subject = $variables['fname'] . " " . $variables['lname'] . " results - " . $test_name;
$headers = "From: test#test.com\n";
$headers .= "Reply-To: test#test.com \n";
$headers .= "MIME-Version: 1.0 \n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1 \n";
$headers .= "Content-Transfer-Encoding: base64";
$message = getMessage( $variables );
$message = rtrim(chunk_split(base64_encode($message)));
foreach ($force_email as $to) {
mail($to, $subject, $message, $headers);
}
I'm trying to hide the form and show the success alert after the mail is mailed.
But everything I do, is ignored by the code, I put header before the mail function, and the mail still sends, it should redirect before the mail sends, tried to break the code before the mail function, and the break functions works.
at list the mail doesn't send.
contact.php:
<div id="innerWrapper">
<h1 class="pageheading"><?=translate('contact_us') ?></h1>
<form class="form-horizontal" action="/ajax/contact.php" method="POST" id="contactForm">
<?php $email = $db->get_row("SELECT email,full_name FROM users WHERE userID = 1");?>
<label><?=translate('your_name') ?>:</label>
<input type="text" name="name" <?php if($usersObject->ID()) {echo 'value = "'. $email->full_name. '"';} else {echo 'placeholder = "First / Last"';}?> class="required input-xlarge"/>
<br/><br/>
<label><?=translate('email') ?>:</label>
<input type="email" name="email" <?php if($usersObject->ID()) {echo 'value = "'. $email->email . '"';} else {echo 'placeholder = "email#example.com"';}?> class="required input-xlarge"/>
<br/><br/>
<label>Subject:</label>
<input type="text" name="<?=translate('subject') ?>" placeholder="Hi" class="required input-xlarge"/>
<br/><br/>
<label><?=translate('message') ?>:</label>
<textarea name="message_to_us" class="input-xlarge required" rows="5" placeholder=""></textarea>
<br/><br/>
<input class="btn btn-large btn-warning" value="<?=translate('contact_btn') ?>" type="submit" name="sbc"/>
</form>
</div>
ajax/contact.php :
if(isset($_POST['sbc'])) {
foreach($_POST as $K=>$V) $_POST[$K] = trim(strip_tags($V));
extract($_POST);
foreach($_POST as $k=>$v) {
if(trim($v) == "")
{
print '<div class="alert alert-error">All fields are required</div>';
exit;
}
}
$body = 'New contact form message on ' . $_SERVER['SERVER_NAME'];
$body .= '<br/>';
$body .= 'Subject : ' . $Subject;
$body .= '<br/>';
$body .= 'Name : '.$name .' / Email : ' . $email;
$body .= '<br/>';
$body .= $message_to_us;
$headers = "From: contact#" . str_replace("www.", "", $_SERVER['SERVER_NAME']) . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
mail(PAYPAL_EMAIL, str_replace("www.", '', $_SERVER["SERVER_NAME"]), $body, $headers);
?>
<script type="text/javascript">
$("#sbc").click(function() {
$("#contactForm").hide('slow');
});
</script>
<?php
print '<div class="alert alert-success">'.translate('thankyou_contact').'</div>';
}else{
print 'Emtpy request';
}
edit:
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
header('Location: join');
mail(PAYPAL_EMAIL, str_replace("www.", '', $_SERVER["SERVER_NAME"]), $body, $headers);
tried to redirect before the mail just to check, but it just ignores the header and still mail the mail.
edit2 :
<script type="text/javascript">
$(document).ready (function() {
$("#sbc").click(function() {
$("#contactForm").hide('slow');
});
});
</script>
not working.
add id= sbc to
<input class="btn btn-large btn-warning" value="<?=translate('contact_btn') ?>" type="submit" name="sbc" id="sbc"/>
This is the error coming while i try to send mail using php.
Failed to load resource: the server responded with a status of 405 (Method Not Allowed) sendmail.php
this is the form
<form action="sendmail.php" method="post" id="contactform" >
<div id='name-error' class='error'>Please enter your name.</div>
<input name="name" placeholder="Name" class="form-control" type="text" id="name">
<div id='email-error' class='error'>Please enter your valid E-mail ID.</div>
<input name="email" placeholder="Email" class="form-control" type="text" id="email">
<div id='subject-error' class='error'>Please enter the subject.</div>
<input name="subject" placeholder="Subject" class="form-control" type="text" id="subject">
<div id='message-error' class='error'>Please enter your message.</div>
<textarea name="message" placeholder="Message" id="message" rows="4" class="form-control"></textarea>
<div id='mail-success' class='success'>Your message has been sent successfully.</div>
<div id='mail-fail' class='error'> Sorry, error occured this time sending your message.</div>
<input type="submit" value="Send Message" class="form-control" id="send-message">
</form>
this is the query
$.post("sendmail.php", $("#contactform").serialize(), function(result){
enter code here if (result == 'sent'){
$('#mail-success').slideDown(500).delay(1000).slideUp(500);
$('#send-message').removeAttr('disabled').attr('value', 'Send Message');
} else{
$('#mail-fail').slideDown(500).delay(1000).slideUp(500);
$('#send-message').removeAttr('disabled').attr('value', 'Send Message');
}
});
}
});
this is the sendmail.php file
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = "info#vonesoft.com";
$to = "mujtaba1004#gmail.com";
$head = "New Contact Lead - VOneSoft";
$body = "Hi , <br /><br />";
$body .= "<table border='1' cellpadding='4' cellspacing='0'>";
$body .= "<tr><td>Name </td><td> " . $name . " </td></tr>";
$body .= "<tr><td>Email </td><td> " . $email . " </td></tr>";
$body .= "<tr><td>Subject </td><td> " . $subject . " </td></tr>";
$body .= "<tr><td>Message </td><td> " . $message . " </td></tr>";
$body .= "</table>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= "From:" . $from "\r\n";
mail($to, $head, $body, $headers);
echo '1';
?>
You forgot to concatenate here
$headers .= "From:" . $from. "\r\n";
-------------^
I have a form. With the following:
HTML:
<form name="feedback_form" method="post" action="" class="feedback_form">
<input type="text" name="field-name" value="İsim" title="İsim" class="field-name form_field">
<input type="text" name="field-email" value="Email" title="Email" class="field-email form_field">
<input type="text" name="field-subject" value="Başlık" title="Başlık" class="field-subject form_field">
<textarea name="field-message" cols="45" rows="5" title="Mesajınız..." class="field-message form_field">Mesajınız...</textarea>
<label for='uploaded_file'>Fotoğrafınızı Yükleyin:</label>
<input type="file" name="field-file" value="File">
<br>
<input type="reset" name="reset" id="reset2" value="Temizle" class="feedback_reset">
<input type="button" name="submit" class="feedback_go" id="submit2" value="Gönder">
</form>
PHP:
<?php
header('Content-Type: text/html; charset=utf-8');
function sendFeedback($feedback_email, $feedback_msg, $feedback_name, $feedback_subject, $feedback_file) {
/* EDIT THIS */
$admin_email = "mymail#gmail.com";
if ($feedback_subject == "Subject" || empty($feedback_subject) ) {
$subj = "Email from your site";
} else {
$subj = $feedback_subject;
}
/* //EDIT THIS */
$message = "
<html>
<head>
<title>Websitenizin emaili</title>
</head>
<body>
<p><a href='mailto:".$feedback_email."'>".$feedback_name."</a> send this message:</p>
<p>".$feedback_msg."</p>
<p>".$subject."</p>
</body>
</html>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
if ($feedback_name!=="Name" && $feedback_email!=="Email" && !empty($feedback_email) && !empty($feedback_msg) && !empty($feedback_name) ) {
if ($feedback_email == "mail_error") {
echo "<span class='ajaxok'>Geçersiz email adresi.</span>";
} else {
mail($admin_email, $subj, $message, $headers);
echo "<span class='ajaxok'>Teşekkürler. Mesajınız gönderilmiştir.</span>";
}
} else {
echo "<span class='ajaxalert'>Lütfen zorunlu alanları doldurunuz.</span>";
}
}
sendFeedback($_POST['email'], $_POST['message'], $_POST['name'], $_POST['subject'], $_POST['file']);
?>
When send a message on this form, send email, working. But only subject, message, name and email. I want add image upload in this php code. But i don't know how can i do it? Please help me.
In the form you have to put enctype="multipart/form-data".
In your php file you can access the file via $_FILES['file'];
Then take a look at this tutorial
I have created a form that pulls a variable from a url using the following code:
<?php $id = $_GET['id']; echo $id; ?>
Using this is link as an example (http://www.mydomain.co.uk/customerform.php?id=12) it would display 12 on the webpage.
What I would like to know, is it possible to stop the web page from loading if there is no varible in the URL e.g ?id=12 ?
Either in php, javascript?
So If you visited the following link, the web page would display:
http://www.mydomain.co.uk/customerform.php?id=12
and if you visited this link (without the variable), the page would not display:
http://www.mydomain.co.uk/customerform.php
Thank you for any help.
Update below...
I have added Krishnanunni's code and it successfully prevents the web page from displaying if the is no vartiable in the url. But adding this code prevents the form submitting...
Is there a way of keeping the url variable when the form is submitted?
Can anyone help? Thanks
<body id="main_body" >
<div id="form_container">
<?
/* only load page is variable is presnt in the URL */
if (!isset($_GET['id']) || empty($_GET['id']))
{
die("Bad Request");
}
?>
<?
/* Mailer with Attachments */
$action = $_REQUEST['action'];
global $action;
function showForm() {
?>
<form id="contact" class="appnitro" name="idform" enctype="multipart/form-data" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" name="action" value="send" />
<input type="hidden" name="MAX_FILE_SIZE" value="10000000"/>
<input name="to_email" type="hidden" id="to_email" value="myemail#domain.co.uk"/>
<div>
<input id="invoice" name="invoice" class="element text medium" type="hidden" maxlength="255" value="<?php $id = $_GET['id']; echo $id; ?>"/>
</div>
<div>
<input id="subject" name="subject" class="element text medium" type="hidden" maxlength="255" value="Enquiry Form - (Invoice: <?php $id = $_GET['id']; echo $id; ?>)"/>
</div>
<label class="description" for="from_name">Name </label>
<div>
<input id="from_name" name="from_name" class="element text medium" type="text" maxlength="255" value=""/>
</div>
<label class="description" for="position">Position </label>
<div>
<input id="position" name="position" class="element text medium" type="text" maxlength="255" value=""/>
</div>
<label class="description" for="uemail"> Email </label>
<div>
<input id="email" name="email" class="element text medium" type="text" maxlength="255" value=""/>
</div>
<label class="description" for="phone"> Phone </label>
<div>
<input id="phone" name="phone" class="element text medium" type="text" maxlength="255" value=""/>
</div>
<input name="Reset" type="reset" class="contactform_small" value="Reset" />
<input name="Submit2" type="submit" class="contactform_small" id="Submit" value="Submit" />
</form>
<?
}
function sendMail() {
if (!isset ($_POST['to_email'])) { //Oops, forgot your email addy!
die ("<p>Oops! You forgot to fill out the email address! Click on the back arrow to go back</p>");
}
else {
$to_name = "MY BUSINESS";
$from_name = stripslashes($_POST['from_name']);
$subject = Trim(stripslashes($_POST['subject']));
$to_email = $_POST['to_email'];
$EmailFrom = Trim(stripslashes($_POST['email']));
// get posted data into local variables
$position = Trim(stripslashes($_POST['position']));
$position2 = Trim(stripslashes($_POST['position2']));
$phone = Trim(stripslashes($_POST['phone']));
$invoice = Trim(stripslashes($_POST['invoice']));
//Let's start our headers
$headers = "From: $EmailFrom<" . $_POST['email'] . ">\n";
$headers .= "Reply-To: <" . $_POST['email'] . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n";
$headers .= "X-Sender: $from_name<" . $_POST['email'] . ">\n";
$headers .= "X-Mailer: PHP4\n";
$headers .= "X-Priority: 3\n"; //1 = Urgent, 3 = Normal
$headers .= "Return-Path: <" . $_POST['email'] . ">\n";
$headers .= "This is a multi-part message in MIME format.\n";
$headers .= "------=MIME_BOUNDRY_main_message \n";
$headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n";
$message = "------=MIME_BOUNDRY_message_parts\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";
/* Add our message, in this case it's plain text. You could also add HTML by changing the Content-Type to text/html */
$message .= "Invoice: ";
$message .= $invoice;
$message .= "\n";
$message .= "\n";
$message .= "My Business Enquiry Form";
$message .= "\n";
$message .= "\n";
$message .= "Contact Details: ";
$message .= "\n";
$message .= "\n";
$message .= "Name: ";
$message .= $from_name;
$message .= "\n";
$message .= "Position: ";
$message .= $position;
$message .= "\n";
$message .= "Email: ";
$message .= $EmailFrom;
$message .= "\n";
$message .= "Phone: ";
$message .= $phone;
$message .= "\n";
$message .= "\n";
// send the message
mail("$to_name<$to_email>", $subject, $message, $headers);
print "Form sent successfully";
}
}
?>
<?
switch ($action) {
case "send":
sendMail();
showForm();
break;
default:
showForm();
}
?>
<div id="footer">
</div>
</div>
</body>
Start your php page with this code
if (!isset($_GET['id']) || empty($_GET['id']))
{
die("Bad Request");
}
This should solve your problem