Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jammer08

macrumors member
Original poster
May 26, 2006
63
0
I am currently hosting my website on a macbook using apache, and I need to add some forms to my site that will submit the info to me via email. I have the forms set up, but when you try to submit a form on the site, you get an error. Anyone know how to correct this? Do I need a mail server running or something? Any help is greatly appreciated.
 
jammer08 said:
I am currently hosting my website on a macbook using apache, and I need to add some forms to my site that will submit the info to me via email. I have the forms set up, but when you try to submit a form on the site, you get an error. Anyone know how to correct this? Do I need a mail server running or something? Any help is greatly appreciated.

You need to set-up a cgi script to handle the mail.
If you don't have time to learn the know-how, in the meantime, try this:
PHP:
<FORM METHOD=POST ACTION="mailto:YOURADDRESS@YOURHOST.COM" ENCTYPE="text/plain">
<INPUT TYPE="text" NAME="username"> : name <BR>
<INPUT TYPE="text" NAME="email"> : email <BR>
comments <BR>
<TEXTAREA NAME="COMMENTS" ROWS="10" WRAP="hard">
</TEXTAREA>
<INPUT NAME="redirect" TYPE="hidden" VALUE="index.html">
<INPUT NAME="NEXT_URL" TYPE="hidden" VALUE="index.html">
<BR>
<INPUT TYPE="submit" VALUE="Send">
<INPUT TYPE="reset" VALUE="Clear">
</FORM>
</CENTER>

substitute YOURADDRESS@YOURHOST.COM with your email address.
Be warned though, the form will be sent by the person visiting your site, not the server, thus if he doesn't have an email client installed, you're S.O.L.

You may want to read this to get you started on the wonderful world of CGI programming ;) http://developer.apple.com/internet/opensource/php.html
 
Palad1 said:
You need to set-up a cgi script to handle the mail.
If you don't have time to learn the know-how, in the meantime, try this:
PHP:
<FORM METHOD=POST ACTION="mailto:YOURADDRESS@YOURHOST.COM" ENCTYPE="text/plain">
<INPUT TYPE="text" NAME="username"> : name <BR>
<INPUT TYPE="text" NAME="email"> : email <BR>
comments <BR>
<TEXTAREA NAME="COMMENTS" ROWS="10" WRAP="hard">
</TEXTAREA>
<INPUT NAME="redirect" TYPE="hidden" VALUE="index.html">
<INPUT NAME="NEXT_URL" TYPE="hidden" VALUE="index.html">
<BR>
<INPUT TYPE="submit" VALUE="Send">
<INPUT TYPE="reset" VALUE="Clear">
</FORM>
</CENTER>

substitute YOURADDRESS@YOURHOST.COM with your email address.
Be warned though, the form will be sent by the person visiting your site, not the server, thus if he doesn't have an email client installed, you're S.O.L.

You may want to read this to get you started on the wonderful world of CGI programming ;) http://developer.apple.com/internet/opensource/php.html

Thanks for the information. That really won't work for my situation... I need it to be send by my server... Thanks for the resource, I will read up and try to figure it out. Thanks again.
 
if you want your server to send it out, then yes you'll need a mail server running. Tiger comes with Postfix already, it's only a matter of enabling it.

Most easily done with Postfix Enabler but can be done by editing a few system conf files - there's a hint here (it's for Panther but i think it still applies).

Then you need to send the mail to Postfix from the form.

Not sure about other alternatives, but it's pretty straightforward in PHP using the mail() function:
Code:
<?

// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "you@yours.com";
$Subject = "Email Subject";
$Name = Trim(stripslashes($_POST['Name'])); 
$Address = Trim(stripslashes($_POST['Address'])); 
$Telephone = Trim(stripslashes($_POST['Telephone'])); 
$Message = Trim(stripslashes($_POST['Message']));

// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (Trim($Name)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contacterror.html\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactok.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactbad.html\">";
}
?>
 
frankblundt said:
if you want your server to send it out, then yes you'll need a mail server running. Tiger comes with Postfix already, it's only a matter of enabling it.

Most easily done with Postfix Enabler but can be done by editing a few system conf files - there's a hint here (it's for Panther but i think it still applies).

Then you need to send the mail to Postfix from the form.

Not sure about other alternatives, but it's pretty straightforward in PHP using the mail() function:
Code:
<?

// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "you@yours.com";
$Subject = "Email Subject";
$Name = Trim(stripslashes($_POST['Name'])); 
$Address = Trim(stripslashes($_POST['Address'])); 
$Telephone = Trim(stripslashes($_POST['Telephone'])); 
$Message = Trim(stripslashes($_POST['Message']));

// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (Trim($Name)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contacterror.html\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

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

THANK YOU! this is what I have been looking for! :)
 
As far as i remember, on a mac you don't need to alter anything in the php.ini file - there's more on that side of things here, but most of it is for Windows) which you might want to check thru - although it says in the default ini file that it will send to Sendmail (the previous mail server that came with macs prior to 10.3, i think), the OS redirects sendmail requests to Postfix automatically
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.