...

View Full Version : issue with $message in a form



malthus23
02-10-2010, 06:15 PM
Hi,
I have an issue with a form I'm trying to adapt. The validation works fine, the sending as well, but the elements from the form are not in the message.

Here is what my code looks like:



// Set the correct HTTP headers
header('Content-Type: text/'.($ajax ? 'plain' : 'html').'; charset=utf-8');

// Extract and trim contactform values
$ref = isset($_POST['ref']) ? trim($_POST['ref']) : '';
$domain = isset($_POST['domain']) ? trim($_POST['domain']) : '';
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
$comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';

// Take care of magic quotes if needed (you really should have them disabled)
set_magic_quotes_runtime(0);
if (get_magic_quotes_gpc())
{
$ref = stripslashes($ref);
$domain = stripslashes($domain);
$name = stripslashes($name);
$email = stripslashes($email);
$comment = stripslashes($comment);
}

// Initialize the errors array which will also be sent back as a JSON object
$errors = NULL;

// Validation
if ($email == '')
{
$errors['email'] = $config['errors']['no_email'];
}
elseif ( ! preg_match('/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?$/iD', $email))
{
$errors['email'] = $config['errors']['invalid_email'];
}

// Validation succeeded
if (empty($errors))
{
$subject = str_replace('%ref%', $ref, $config['subject']);

$todayis = date("l, F j, Y, g:i a") ;

// This is where I think my issue is!
$message = ' Date: $todayis [EST] \n
Nom: &name \n
Modele reference: &ref \n
Nom de domaine: &domain \n
Commentaire: &comment \n
';

$headers = 'Content-Type: text/plain; charset=utf-8'."\r\n";
$headers .= 'From: '.$email;

if ( ! mail($config['recipient'], $subject, $message, $headers))
{
$errors['server'] = 'Il y a un probleme avec notre serveur, nous en sommes désolés. '.
'Envoyer votre message directement: '.$config['recipient'].'Merci.';
}
}



And I receive the following in the email (header is correct):
Date: $todayis [EST] \n
Nom: &name \n
Modele reference: &ref \n
Nom de domaine: &domain \n
Commentaire: &comment \n

Thanks,
M.

MattF
02-10-2010, 06:21 PM
$message = ' Date: '.$todayis.' [EST]'."\n"
.'Nom: '.$name.'."\n"
.'Modele reference: '.$ref.'."\n"
.'Nom de domaine: '.$domain.'."\n"
.'Commentaire: '.$comment.'."\n";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum