» »

Pomoč pri kontakt formi

Pomoč pri kontakt formi

Dejan209 ::

Živjo,

imam eno težavo in sicer sem pobral en template in mi ne rata urediti contact forme.

v htmlju imam sledečo formo:

<form id="contact-form">
								<fieldset>
									<label>
										<input type="text" value="Name" onBlur="if(this.value=='') this.value='Name'" onFocus="if(this.value =='Name' ) this.value=''" />
									</label>
									<label>
									  <input type="text" value="Email" onBlur="if(this.value=='') this.value='Email'" onFocus="if(this.value =='Email' ) this.value=''" />
									</label>
									<label>
									  <input type="text" value="Phone" onBlur="if(this.value=='') this.value='Phone'" onFocus="if(this.value =='Phone' ) this.value=''" />
									</label>
									<textarea onBlur="if(this.value=='') this.value='Message'" onFocus="if(this.value =='Message' ) this.value=''">Message</textarea>
									<div class="buttons-wrapper">
										<a class="button" onClick="document.getElementById('contact-form').reset()">Clear</a>
										<a class="button" onClick="document.getElementById('contact-form').submit()">Send</a>
									</div>
								</fieldset>
							</form>


zraven imam še v BIN mapi mailhandler.php
<?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";
	if($_POST['state']!='nope'){		
		$messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";
		$messageBody .= '<br>' . "\n";
	}
	if($_POST['phone']!='nope'){		
		$messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
		$messageBody .= '<br>' . "\n";
	}	
	if($_POST['fax']!='nope'){		
		$messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</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";
	}
?>


in mailhandler.ashx
<%@ 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("mail.google.com"));
		string owner_email = context.Request.Form.Get("xxx@gmail.com");
		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;
		}
	}
}


in zadeva ko dam na net mi nekako ne dela?! ve kdo, kje sem zajebal stvar ? oz. me usmeri dalje, kjer bi lahko dobil kakšno informacijo ?

hvala! :)

dukedl ::

jz bi nahitr reku, da bi manjka action v form oznaki

Glej pri Submit Button
http://www.w3schools.com/html/html_form...
lp dukedl

HardFu ::

ce hoces dobit spremenljivko $_POST["email"], potem rabis input tag, ko ma name="email" atribut, isto velja za ostala polja (name, fax, state ....)
http://codeable.io

bzp ::

A to si iz treh tutorialov svojo verzijo skupaj spravil? Ker IMHO je en file preveč, ostala dva pa nista pravilno "zvezana" skupaj.

Dejan209 ::

ciau, v bistvu sem pobral en contact form in to to je blo zraven.

Vzdevek ::

Kaj pa v mailhandler.ashx a ni tukaj potrebno vnesti svojega maila ali si to že storil?

        string owner_email = context.Request.Form.Get("xxx@gmail.com");


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

Davčne blagajne (strani: 1 2 3 424 25 26 27 )

Oddelek: Programiranje
1344331404 (71407) Macketina
»

Web services - Neveljavni karakterji v XML

Oddelek: Programiranje
314096 (3208) boolsheat
»

Visual Basic

Oddelek: Programiranje
313417 (2443) cekr
»

Kontakt obrazec

Oddelek: Izdelava spletišč
62055 (1900) betmen
»

[ASP.NET] send mail

Oddelek: Programiranje
51260 (1197) Microsoft

Več podobnih tem