Jump to content
Lizard Wizard Coding Club

cant get contact form to work......


Recommended Posts

<?php

 

if(!$_POST) exit;

 

$to = $_POST['emailto'];

 

$subject = 'Contact from '.$_POST['blogname'];

$headers = 'From: '.$_POST['contact_email'];

 

$date = date ("l, F jS, Y");

$time = date ("h:i A");

 

$msg = 'Submitted by '.$_POST['contact_name']." $date at $time.\n\n";

 

$msg .= $_POST['contact_message'];

 

 

if (empty($_POST['contact_email']) || !validEmail($_POST['contact_email']))

{

$return['invalid_email'] = 1;

}

if (empty($_POST['contact_name']))

{

$return['invalid_name'] = 1;

}

if (empty($_POST['contact_message']))

{

$return['invalid_message'] = 1;

}

 

// if no previous errors have been set

if (empty($return))

{

if (mail($to, $subject, $msg, $headers))

{

$return['success'] = 1;

}

else

{

$return['success'] = 0;

}

}

echo json_encode($return);

 

 

function validEmail($email)

{

$isValid = true;

$atIndex = strrpos($email, "@");

if (is_bool($atIndex) && !$atIndex)

{

$isValid = false;

}

else

{

$domain = substr($email, $atIndex+1);

$local = substr($email, 0, $atIndex);

$localLen = strlen($local);

$domainLen = strlen($domain);

if ($localLen < 1 || $localLen > 64)

{

// local part length exceeded

$isValid = false;

}

else if ($domainLen < 1 || $domainLen > 255)

{

// domain part length exceeded

$isValid = false;

}

else if ($local[0] == '.' || $local[$localLen-1] == '.')

{

// local part starts or ends with '.'

$isValid = false;

}

else if (preg_match('/\\.\\./', $local))

{

// local part has two consecutive dots

$isValid = false;

}

else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))

{

// character not valid in domain part

$isValid = false;

}

else if (preg_match('/\\.\\./', $domain))

{

// domain part has two consecutive dots

$isValid = false;

}

else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',

str_replace("\\\\","",$local)))

{

// character not valid in local part unless

// local part is quoted

if (!preg_match('/^"(\\\\"|[^"])+"$/',

str_replace("\\\\","",$local)))

{

$isValid = false;

}

}

if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))

{

// domain not found in DNS

$isValid = false;

}

}

return $isValid;

}

Link to post
Share on other sites

i ve been informed by the web host that i cant use any php script other than the formail that they use. i have to change the script for the form cause nothing works on it as an error on page comes up at the bottom. im not to sure how to change the script in the new form though. sorry im a novice ......:(

Link to post
Share on other sites

You can "Watch" the topic, which depending on your settings (http://www.killersites.com/community/index.php?app=core&module=usercp&tab=core&area=notifications) will allow you to receive email when people reply.

 

Regarding your form... Assuming you are brand new to PHP (I think you said you are?) you may need to have someone who is familiar with PHP/Wordpress help you out (for a small fee, if necessary.) It sounds like you will need to create a custom PHP based form (probably within a Wordpress custom page template) that integrates with the form processing script your host has provided you.

 

Can you post the PHP script your host expects you to use, plus any links to documentation on it that your host may have provided? I can take a look, but as I said above, it may be a bit difficult to help you with this - short of having someone who is experienced write everything for you.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...