Že nakaj časa se ubadam pa mi nikakor ne rati skonfigurirati speltni obrazec da pošlje mail. Sedaj imam nekako takole:
v fileju index5.html
V direktoriju js imam file contact-form.js
in v direktoriju bin pa imam fajla MailHandler.ashx in MailHandler.php
MailHandler.ashx
MailHandler.php
Vse sem tudi prenesel na web strežnik ampak sedaj ne vem kam moram vpisati email naslov kamor naj se kontaktni obrazec pošlje, oziroma kaj moram še popraviti ?
Hvala za pomoč
v fileju index5.html
Citat:
<h5 class="h5-pad">KONTAKTNI OBRAZEC</h5>
<div id="contact_form">
<form id="contact-form" method="post" class="main-contacts">
<fieldset>
<input type="hidden" name="owner_email" id="owner_email" value="" />
<input type="hidden" name="serverProcessorType" id="serverProcessorType" value="php" />
<input type="hidden" name="smtpMailServer" id="smtpMailServer" value="localhost" />
<input type="hidden" name="stripHTML" id="stripHTML" value="true" />
<div class="rowElem">
<input type="text" name="name" id="name" value="Ime:" onFocus="if(this.value=='name:'){this.value=''}" onBlur="if(this.value==''){this.value='Ime:'}" />
<label class="error" for="name" id="name_error">*To polje je potrebno obvezno izpolniti.</label>
<label class="error" for="name" id="name_error2">*To ni pravo ime.</label>
</div>
<div class="rowElem">
<input type="text" name="email" id="email" value="E-mail:" onFocus="if(this.value=='E-mail:'){this.value=''}" onBlur="if(this.value==''){this.value='E-mail:'}" />
<label class="error" for="email" id="email_error">*To polje je potrebno obvezno izpolniti.</label>
<label class="error" for="email" id="email_error2">*Ne veljaven email naslov.</label>
</div>
<div class="rowElem">
<input type="text" name="phone" id="phone" value="Telefon:" onFocus="if(this.value=='phone:'){this.value=''}" onBlur="if(this.value==''){this.value='Telefon:'}" />
<label class="error" for="phone" id="phone_error">*To polje je potrebno obvezno izpolniti.</label>
<label class="error" for="phone" id="phone_error2">*Ni veljavna telefonska številka.</label>
</div>
<div class="textarea-box">
<textarea onFocus="if(this.value=='Sporočilo:'){this.value=''}" onBlur="if(this.value==''){this.value='Sporočilo:'}" name="message" id="message">Sporočilo:</textarea>
<label class="error" for="message" id="message_error">*Obvezno izpolniti.</label>
<label class="error" for="message" id="message_error2">*Sporočilo je prekratko.</label>
</div>
<div class="alignright">
<a href="#" id="clear" class="button1" ><span>ZbriŠI</span></a><a href="#" id="submit" class="button1" ><span>POŠLJI</span></a>
V direktoriju js imam file contact-form.js
Citat:
$(function(){
$('.error').hide();
// reset form and hide all errors
$("a#clear").click(function(){
$('.error').hide();
$('form#contact-form').clearForm();
});
// show message error if after editing
// the name field contains improper value
$("input#name").blur(function(){
if(validateInput('name')){
if(!validateName()){
$("label#name_error").hide();
$("label#name_error2").show();
}
}else{
$("label#name_error2").hide();
}
});
// show message error if after editing
// the email field contains improper value
$("input#email").blur(function(){
if(validateInput('email')){
if(!validateEmail()){
$("label#email_error").hide();
$("label#email_error2").show();
}
}else{
$("label#email_error2").hide();
}
});
// show message error if after editing
// the phone field contains improper value
$("input#phone").blur(function(){
if(validateInput('phone')){
if(!validatePhone()){
$("label#phone_error").hide();
$("label#phone_error2").show();
}
}else{
$("label#phone_error2").hide();
}
});
// show message error if after editing
// the message field contains improper value
$("textarea#message").blur(function(){
if(validateTextArea('message')){
if(!validateMessage()){
$("label#message_error").hide();
$("label#message_error2").show();
}
}else{
$("label#message_error2").hide();
}
});
$("input#name").keydown(function(){
if(validateInput('name')){
$("label#name_error").hide();
}
if(validateName()){
$("label#name_error2").hide();
}
});
$("input#email").keydown(function(){
if(validateInput('email')){
$("label#email_error").hide();
}
if(validateEmail()){
$("label#email_error2").hide();
}
});
$("input#phone").keydown(function(){
if(validateInput('phone')){
$("label#phone_error").hide();
}
if(validatePhone()){
$("label#phone_error2").hide();
}
});
$("textarea#message").keydown(function(){
if(validateTextArea('message')){
$("label#message_error").hide();
}
if(validateMessage()){
$("label#message_error2").hide();
}
});
var owner_email = $("input#owner_email").val();
if(!isValidEmailAddress(owner_email)){
$('#contact_form').html("<label class='error'>*Owner email is not valid</label>")
}
$("a#submit").click(function(){
// validate and process form
var quit = false;
if(validateName()){
name = validateName();
$("label#name_error").hide();
$("label#name_error2").hide();
}else if(validateInput('name')){
$("label#name_error").hide();
$("label#name_error2").show();
}else{
$("label#name_error").show();
$("label#name_error2").hide();
quit = true;
}
if(validateEmail()){
email = validateEmail();
$("label#email_error").hide();
$("label#email_error2").hide();
}else if(validateInput('email')){
$("label#email_error").hide();
$("label#email_error2").show();
}else{
$("label#email_error").show();
$("label#email_error2").hide();
quit = true;
}
if(validatePhone()){
phone = validatePhone();
$("label#phone_error").hide();
$("label#phone_error2").hide();
}else if(validateInput('phone')){
$("label#phone_error").hide();
$("label#phone_error2").show();
}else{
$("label#phone_error").show();
$("label#phone_error2").hide();
quit = true;
}
if(validateMessage()){
message = validateMessage();
$("label#message_error").hide();
$("label#message_error2").hide();
}else if(validateTextArea('message')){
$("label#message_error").hide();
$("label#message_error2").show();
}else{
$("label#message_error").show();
$("label#message_error2").hide();
quit = true;
}
if(quit){
return false;
}
var stripHTML = $("input#stripHTML").val();
var smtpMailServer = $("input#smtpMailServer").val();
var dataString = 'name=' + name + '&email=' + email + '&phone=' + phone + '&message=' + message + '&owner_email=' + owner_email + '&stripHTML=' + stripHTML + '&smtpMailServer=' + smtpMailServer;
var serverProcessorType = $("input#serverProcessorType").val();
if(serverProcessorType == 'asp'){
fileExtension = 'ashx';
}else{
fileExtension = serverProcessorType;
}
var mailHandlerURL = "bin/MailHandler." + fileExtension;
$.ajax({
type: "POST",
url: mailHandlerURL,
data: dataString,
success: function(){
$('.error').hide();
$('form#contact-form').clearForm();
$('#contact_form').html("<div class='download-box'>Contact form submitted!</div>")
.append("<br><label for='message'><b>We will be in touch soon.</b></label>")
.hide()
.fadeIn(1500, function(){
$('#contact_form').append("<br><br><a id='back' onclick='window.location.reload(); return false;' class='button'>back</a>");
});
}
});
return false;
});
});
$.fn.clearForm = function(){
return this.each(function(){
var type = this.type, tag = this.tagName.toLowerCase();
if (tag == 'form'){
return $(':input',this).clearForm();
}
if (type == 'text' || type == 'password' || tag == 'textarea'){
this.value = '';
}else if (type == 'checkbox' || type == 'radio'){
this.checked = false;
}else if (tag == 'select'){
this.selectedIndex = -1;
}
});
};
function isValidName(name){
var pattern = new RegExp(/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/);
return pattern.test(name);
}
function isValidEmailAddress(emailAddress){
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}
function isValidPhoneNumber(phoneNumber){
var pattern = new RegExp(/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/);
return pattern.test(phoneNumber);
}
function validateName(){
var name = $("input#name").val();
if(isValidName(name)){
return name;
}else{
return false;
}
}
function validateEmail(){
var email = $("input#email").val();
if(!isValidEmailAddress(email)){
return false;
}else{
return email;
}
}
function validatePhone(){
var phone = $("input#phone").val();
if(!isValidPhoneNumber(phone)){
return false;
}else{
return phone;
}
}
function validateMessage(){
var message = $("textarea#message").val();
if(message.length < 10){
return false;
}else{
return message;
}
}
// make sure visitor does not input a blank field
function validateInput(field){
var fieldObject = $("input#" + field + "").val();
if(fieldObject.length < 1){
return false;
}else{
return true;
}
}
function validateTextArea(field){
var fieldObject = $("textarea#" + field + "").val();
if(fieldObject.length < 1){
return false;
}else{
return true;
}
}
in v direktoriju bin pa imam fajla MailHandler.ashx in MailHandler.php
MailHandler.ashx
Citat:
<%@ WebHandler Language="C#" Class="Handler" Debug="true" %>
using System;
using System.Web;
using System.Net.Mail;
using System.Text.RegularExpressions;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
SmtpClient mailClient = new SmtpClient(context.Request.Form.Get("smtpMailServer"));
string owner_email = context.Request.Form.Get("owner_email");
string subject = "A message from your site visitor " + context.Request.Form.Get("name");
string email = context.Request.Form.Get("email");
string messageBody = "";
messageBody += "<p>Visitor: " + context.Request.Form.Get("name") + "</p>\n";
messageBody += "<br>\n";
messageBody += "<p>Email Address: " + context.Request.Form.Get("email") + "</p>\n";
messageBody += "<br>\n";
messageBody += "<p>Phone Number: " + context.Request.Form.Get("phone") + "</p>\n";
messageBody += "<br>\n";
messageBody += "<p>Message: " + context.Request.Form.Get("message") + "</p>\n";
MailMessage message = new MailMessage();
try{
message.From = new MailAddress(email.ToString());
}catch (FormatException e) {
context.Response.Write(e.Message);
}
message.To.Add(owner_email);
message.Subject = subject;
if(context.Request.Form.Get("stripHTML") == "true"){
message.IsBodyHtml = false;
messageBody = Regex.Replace(messageBody, "<.*?>", string.Empty);
}else{
message.IsBodyHtml = true;
}
message.Body = messageBody;
try{
mailClient.Send(message);
}catch (SmtpException e) {
context.Response.Write("mail failed");
}
context.Response.Write("mail sent");
}
public bool IsReusable {
get {
return false;
}
}
}
MailHandler.php
Citat:
<?php
$owner_email = $_POST["owner_email"];
$headers = 'From:' . $_POST["email"];
$subject = 'A message from your site visitor ' . $_POST["name"];
$messageBody = "";
$messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
$messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
$messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
$messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
if($_POST["stripHTML"] == 'true'){
$messageBody = strip_tags($messageBody);
}
try{
if(!mail($owner_email, $subject, $messageBody, $headers)){
throw new Exception('mail failed');
}else{
echo 'mail sent';
}
}catch(Exception $e){
echo $e->getMessage() ."\n";
}
?>
Vse sem tudi prenesel na web strežnik ampak sedaj ne vem kam moram vpisati email naslov kamor naj se kontaktni obrazec pošlje, oziroma kaj moram še popraviti ?
Hvala za pomoč