Jump to content

[SOLVED] Blank instead of email address in "From" in email sent from form


kdreg

Recommended Posts

Messages received from a form come through with no email address (totally blank) in from field. I can't spot the error in the code. The confirmation page is also not picking up the "Name" value. The values for "name" and "id" on the original form that's submitted are in the same case as below (i.e., Name, Email, Message). Can someone help, please?

 

Thank you.

 

<?php
$PageTitle = "Contact Form";
$Name = stripslashes(trim($Name));
$Email = stripslashes(trim($Email));
$Message='';
$ip = $ip;

foreach($HTTP_POST_VARS as $key => $value) { 
	if ($value != "");
		$Message .= $key . ": " . stripslashes(trim($value)) . "\n";
}

session_start();
if (isset($_SESSION['mycookie']) && $_SESSION['mycookie'] == 'okay')
{

// kill if hijack attempt

if (preg_match(' /[\r\n,;\'"]/ ', $_POST['Email'])) {

// if (preg_match(' /[(bcc),\r\n,;\'"]/ ', $_POST['Email'])) {

mail("[email protected]", "Form Hijack Attempt_a", "A spam relay was attempted from the Web site and was blocked.", "From:SpamMonitor"); 
	die();
  }
else {

//	if(eregi("MIME-Version:",$postVars)) { 
//	if(eregi("MIME-Version: ",$HTTP_POST_VARS)) { 
if(eregi("MIME-Version: ",$_POST['Name'].$_POST['Email'].$_POST['Message'])) { 
	mail("[email protected]", "Form Hijack Attempt_b", "A spam relay was attempted from the Web site and was blocked.", "From:SpamMonitor"); 
	die(); 
} 
}

      mail("[email protected]","Contact Form","$Message","From: $Name <$Email>"); 
      header("Location: thanks.php?Name=$Name"); }
  
 else {
// submit did not come from contact.php script
// where a session cookie should have been set
exit;
}

?> 

Thank you for your help, that worked for the email address! I changed it, so now the email address appears as it should.

 

For some reason the value still isn't being picked up in the confirmation page. It shows correctly in the url of the confirmation page the sender is served after the form is submitted:

 

http://www.hcafa.org/forms/thanks.php?Name=My Name

 

but in the body of the confirmation page, it doesn't, it shows up like this:

 

Thank you, , I will be in contact with you as soon as possible if your message requires a reply.

 

Thank you, <?php echo $Name ?>, I will be in contact with you as soon as possible
if your message requires a reply.

 

That also used to work in my forms.

 

I tried this:

 

Thank you, <?php echo $_Post['Name'] ?>, I will be in contact with you as soon as possible
if your message requires a reply.

 

That didn't work either. It's been a year since I've really done any php coding and I've forgotten about everything I'd learned. So I'm not sure why that's not working either, and why things that used to don't anymore.

 

Thanks again.

From what I've read, it might be a change in the register globals setting on the server that might account for why this isn't working now.

 

I've searched on google and through some of the tutorials and snippets, but I just can't find what I'm doing wrong that I just get

 

possible, , if your

 

instead of

 

possible, Richard, if your...

 

Why is the name appearing okay in the URL but not being passed on to the php code within the line of text?

 

Thanks...

No one can steer me in the right direction? I just spent hours scanning my computer for viruses because one seemingly innocuous website I'd googled in search of help attempted to download the vbs/psyme virus to my computer. I trust this website.

 

I'm very rusty after a year's hiatus. The variable is getting passed to the url, but not to the page. I can't figure out what I'm missing in my header redirect:

 

header("Location: thanks.php?Name=$Name"); }

 

The url picks up the person's name, but it's not being passed to the body of the page:

 

Thank you, <?php echo $Name ?>, I will be in contact with you as soon as possible
...

<?php

header("Location: thanks.php?Name=$name");

?>

 

<?php

$name = $_GET["Name"];

echo "Thank you, $Name, I will be in contact with you as soon as possible\n...";

?>

 

Over the last year the register globals default has changed, so you have to specifically define that your code is reading $name from $_GET or $_POST. Can be fixed with something like this though:

 

<?php

foreach($_REQUEST as $key => $value) {
$$key = $value;
}

?>

 

That code will then enable you to use the names of the get variables without doing $_GET all the time :)

Thank you very, very much, chigley. Now I understand much better why it's happening now and what I was doing wrong. After the first answer I had added the code on the processing page, which took care of the blank name in the "from" field in my inbox, but I didn't add it on the confirmation page to make it pick up the name in the body text there. I appreciate the help and explanation.

 

 

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.