Page 1 of 1

Help with Form

Posted: Mon Sep 04, 2006 4:08 am
by bradymills
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi All,

I have a PHP email form setup on my website. The form works fine, except that the "From:" field is not populated with the emailer's address when it comes to my email, I simply get the domain of the site it was sent from. The "Reply-to:" is correct though.. Can someone look at my code and tell me what I'm doing wrong? I'm sure it's a simple fix...
Here's the HTML form:
[syntax="html"]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="robots" content="noindex, nofollow" />
<title>Cutthroat Junction: Mailing List</title>
<style type="text/css" media="all">
input {
	background-color: #000000;
	border: 1px solid #FFFFFF;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 80%;
	font-weight: bold;
	color: #fff;
}

</style>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>
<body style="margin-top: 0px; margin-left: 0px;">
<form name="mailist" id="mailist" method="post" action="action.php">
<div align="center" style="font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 80%; padding-left: 0px; padding-top: 0px;">Mailing List Signup : &nbsp; 
  <input name="email" type="text" onblur="MM_validateForm('email','','NisEmail');return document.MM_returnValue" size="40%" maxlength="225"/>
&nbsp;&nbsp;&nbsp;
<input type="submit" value="Submit" name="submit"/></div>
</form>
</body>
</html>

Here's the PHP, action script:[/syntax]

Code: Select all

<?php
$EmailFrom = stripslashes($_POST['email']);
$EmailTo = "brady@bradymills.com";
$Subject = "Join CTJ Mailist";
// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}
// prepare email body text
$Body = "Add me to the CTJ mailing list.";
$Body .= "--------------------------------------------------------------";
$Body .= "\n";
$Body .= "Email:    ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "--------------------------------------------------------------";
$Body .= "\n";
$Body .="End of Message";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: " . $EmailFrom . "\n" . "Return-Path: " . $EmailFrom . "\n" . "Reply-to: " . $EmailFrom );

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Sep 04, 2006 5:14 am
by volka
Maybe your sendmail is configured that way to prevent spamming and spoofing.

So my code is correct?

Posted: Mon Sep 04, 2006 5:28 am
by bradymills
So my code is correct? If so, is it possible to change the configuration of sendmail -- or is that typically up to my host?

Re: So my code is correct?

Posted: Mon Sep 04, 2006 5:37 am
by volka
bradymills wrote:or is that typically up to my host?
The answer is probably: No, you cannot.
Unless it's your own machine or a root/v-server or similar.

Thanks

Posted: Mon Sep 04, 2006 5:39 am
by bradymills
Well, at least I now know it's not my code. Thanks for your help!

Posted: Mon Sep 04, 2006 5:43 am
by volka
If I remember correctly
$success = mail($EmailTo, $Subject, $Body, "From: " . $EmailFrom . "\n" . "Return-Path: " . $EmailFrom . "\n" . "Reply-to: " . $EmailFrom );
should be

Code: Select all

$success = mail($EmailTo, $Subject, $Body, "From: " . $EmailFrom . "\r\n" . "Return-Path: " . $EmailFrom . "\r\n" . "Reply-to: " . $EmailFrom );
Might be wrong, might be irrelevant.

I'll try that too

Posted: Mon Sep 04, 2006 5:46 am
by bradymills
Thanks. I'll try that too, just to see if it makes a difference.

Posted: Mon Sep 04, 2006 8:20 am
by feyd
If you continue to have problems in creating this email, you may want to try using a mailing library such as Swift or phpMailer.