Jump to content

php contact form help


bciprianp

Recommended Posts

Hi, i have a php contact form that is managed with ajax, but i cant get it to work properlly.

Here is the contact form on my demo site:

http://www.bcpdemo.8...om/contact.html

I receive the name and the message but not the email, instead of email i get a subject filled with the name.

Thanks alot for the help guys.

 

here is how it looks in my yahoo inbox:

 

1evw2b.jpg

 

here is how it looks when i enter the message:

 

2mnqjr6.jpg

 

and here is the php script:

 

1.config_php

 

<?php

 

define("WEBMASTER_EMAIL", 'yourname@email.com');

 

?>

 

2.contact.php

 

include 'config.php';

error_reporting(E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

 

if ($post) {

include 'functions.php';

$name = stripslashes($_POST['name']);

$email = trim($_POST['email']);

$message = stripslashes($_POST['message']);

 

$error = '';

 

// Check name

if (!$name) {

$error .= 'Please enter your name.<br />';

}

// Check email

if (!$email) {

$error .= 'Please enter your e-mail adress.<br />';

}

if ($email && !ValidateEmail($email)) {

$error .= 'Invalid e-mail adress !<br />';

}

// Check message (length)

if (!$message || strlen($message) < 1) {

$error .= "Please enter your message.";

}

 

if (!$error) {

$subject = "your subject";

$messageform = stripslashes($_POST['message']);

$message = "Subject: " . $subject . "\n\nFrom: " . $name . "\n\nMessage: " . $messageform;

$mail = mail(WEBMASTER_EMAIL, $subject, $message, "From: " . $name . " <" . $email . ">\r\n"

. "Reply-To: " . $email . "\r\n"

. "X-Mailer: PHP/" . phpversion());

if ($mail) {

echo 'OK';

}

} else {

echo '<div class="notification_error">' . $error . '</div>';

}

}

?>

 

3.functions.php

 

<?php

function ValidateEmail($email)

{

 

$regex = '/([a-z0-9_.-]+)'. # name

 

'@'. # at

 

'([a-z0-9.-]+){2,255}'. # domain & possibly subdomains

 

'.'. # period

 

'([a-z]+){2,10}/i'; # domain extension

 

if($email == '') {

return false;

}

else {

$eregi = preg_replace($regex, '', $email);

}

 

return empty($eregi) ? true : false;

}

?>

 

Thanks alot for your help guys.

Link to comment
Share on other sites

Have you tried putting just the email after From: in your 4th parameter to the mail function?

 

It looks like you're trying to achieve something like this:

From: Joe < joe@email.com

Maybe, yahoo doesn't like that? I would remove $name and and "<" sign, leave just email after From:, and see what happens.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.