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", '[email protected]');

 

?>

 

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
https://forums.phpfreaks.com/topic/274208-php-contact-form-help/
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 < [email protected]

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.