Jump to content

formmail.pl sending form mail?


kanala

Recommended Posts

I recently hosted my website on a new server (if that's the correct way to say it), but I realised it doesn't have a program whcih sends emails directly from forms to my email address. So I looked on the web and found a formmail.pl but I don't understand how to use it, anyone got any ideas? I need a form like a contact us form on my website which sends the feedback and comments to my email inbox.Thanks

Link to comment
Share on other sites

First you need to find out what your server supports. The script you found is a Perl script, so find out if your server runs Perl or PHP or ASP or Coldfusion or what.
Thankfully because awardspace is so good (recommended) it supports PHP, ASP, PERL, CGI-BIN?, SSI?, and some other stuff.
Link to comment
Share on other sites

Thankfully because awardspace is so good (recommended) it supports PHP, ASP, PERL, CGI-BIN?, SSI?, and some other stuff.
wow 4 people reading this topic lol...hmm someone should delete this.
Link to comment
Share on other sites

You can use this PHP script, save it as formmail.php:

<?php$recipient = "user@domain.com";$subject = "Online contact";$from = "webmaster@{$_SERVER['HTTP_HOST']}";$redirect = "";if (isset($_POST['redirect'])){  $redirect = $_POST['redirect'];  unset($_POST['redirect']);}$body = "An online message has been received on {$_SERVER['HTTP_HOST']}";if ($_SERVER['HTTP_REFERER'] != "")  $body .= " from {$_SERVER['HTTP_REFERER']}";$body .= "\n\n";foreach ($_POST as $key => $val){  $body .= "{$key}: {$val}\n";}if (!@mail($recipient, $subject, $body, "From: {$from}"))  echo "The email could not be sent.";elseif ($redirect != "")  header("Location: {$redirect}");?>

Edit the top 2 lines to change the recipient of the emails and the subject if you want to. You can edit the third line if you want to change the "from" address on the email.For the HTML form, the only thing you really need to notice is the hidden form element called "redirect". Add whatever page you want the user to be redirected to after they submit the form, and make sure the form action is formmail.php and the form method is "post".

<html>  <head>	<title>Formmail test</title>  </head>  <body>  <form action="formmail.php" method="post">	<input type="hidden" name="redirect" value="thanks.html">	First Name: <input type="text" name="first_name"><br>	Last Name: <input type="text" name="last_name"><br>	Email: <input type="text" name="email"><br>	Phone: <input type="text" name="phone"><br>	Comments: <textarea name="comments" rows="3" cols="40"><br>	<input type="submit">  </form></html>

Link to comment
Share on other sites

About 5 minutes to write and test it, it's not very complicated.
Is it possible to change the subject of the email via the html form? e.g. <input type="hidden" value="subject"> or something? Will I need a separate PHP script for every different type of form?
Link to comment
Share on other sites

Yeah, it works. Remove the @ symbol before the mail function to see the error that it is generating.If you want to put the subject in a hidden tag, replace the $subject declaration in the code with this:

$subject = "Default subject";if (isset($_POST['subject'])){  $subject = $_POST['subject'];  unset($_POST['subject']);}

Link to comment
Share on other sites

Yeah, it works. Remove the @ symbol before the mail function to see the error that it is generating.If you want to put the subject in a hidden tag, replace the $subject declaration in the code with this:
$subject = "Default subject";if (isset($_POST['subject'])){  $subject = $_POST['subject'];  unset($_POST['subject']);}

It still says The email could not be sent.The form is here www.buyer.takeawaydvds.com
Link to comment
Share on other sites

Yeah, it works. Remove the @ symbol before the mail function to see the error that it is generating.
Did you do that? Change this line:if (!@mail($recipient, $subject, $body, "From: {$from}"))to this:if (!mail($recipient, $subject, $body, "From: {$from}"))
Link to comment
Share on other sites

Did you do that? Change this line:if (!@mail($recipient, $subject, $body, "From: {$from}"))to this:if (!mail($recipient, $subject, $body, "From: {$from}"))
Yep, still the same thing happens.
Link to comment
Share on other sites

Try this version:

<?phpini_set("display_errors", 1);error_reporting(E_ALL);$recipient = "user@domain.com";$subject = "Online contact";$from = "webmaster@{$_SERVER['HTTP_HOST']}";$redirect = "";if (isset($_POST['redirect'])){  $redirect = $_POST['redirect'];  unset($_POST['redirect']);}$body = "An online message has been received on {$_SERVER['HTTP_HOST']}";if ($_SERVER['HTTP_REFERER'] != "")  $body .= " from {$_SERVER['HTTP_REFERER']}";$body .= "\n\n";foreach ($_POST as $key => $val){  $body .= "{$key}: {$val}\n";}$body = wordwrap($body, 70);if (!mail($recipient, $subject, $body, "From: {$from}")){  echo "The email could not be sent.";  echo "<br>Safe mode: " . ini_set("safe_mode");  echo "<br>Log errors: " . ini_get("log_errors");  echo "<br>Error log: " . ini_get("error_log");}elseif ($redirect != "")  header("Location: {$redirect}");?>

Link to comment
Share on other sites

This time I got The email could not be sent.Warning: Wrong parameter count for ini_set() in /home/www/buyer.takeawaydvds.com/formmail.php on line 32Safe mode:Log errors:Error log:

Link to comment
Share on other sites

Whoops, replace this line:echo "<br>Safe mode: " . ini_set("safe_mode");with this:echo "<br>Safe mode: " . ini_get("safe_mode");And add this one too:echo "<br>Disabled functions: " . ini_get("disable_functions");

Link to comment
Share on other sites

my script so far

<?phpini_set("display_errors", 1);error_reporting(E_ALL);$recipient = "info@takeawaydvds.com";$subject = "Online contact";$from = "webmaster@{$_SERVER['HTTP_HOST']}";$redirect = "";if (isset($_POST['redirect'])){  $redirect = $_POST['redirect'];  unset($_POST['redirect']);}$body = "An online message has been received on {$_SERVER['HTTP_HOST']}";if ($_SERVER['HTTP_REFERER'] != "")  $body .= " from {$_SERVER['HTTP_REFERER']}";$body .= "\n\n";foreach ($_POST as $key => $val){  $body .= "{$key}: {$val}\n";}$body = wordwrap($body, 70);if (!mail($recipient, $subject, $body, "From: {$from}")){  echo "The email could not be sent.";  echo "<br>Safe mode: " . ini_get("safe_mode");  echo "<br>Log errors: " . ini_get("log_errors");  echo "<br>Error log: " . ini_get("error_log");  echo "<br>Disabled functions: " . ini_get("disable_functions");}elseif ($redirect != "")  header("Location: {$redirect}");?>

But another error message comes up:The email could not be sent.Safe mode:Log errors:Error log:Disabled functions: chown, chgrp

Link to comment
Share on other sites

This is weird, I haven't seen this before where the mail function returns false but doesn't generate an error.Put this in the script somewhere:echo $_SERVER['HTTP_HOST'];And just make sure it prints out the domain name, like buyer.takeawaydvds.com. Also, you can remove all of this:echo "<br>Safe mode: " . ini_get("safe_mode");echo "<br>Log errors: " . ini_get("log_errors");echo "<br>Error log: " . ini_get("error_log");echo "<br>Disabled functions: " . ini_get("disable_functions");And add in this stuff to check the mail config:echo "<br>SMTP: " . ini_get("SMTP");echo "<br>smtp_port: " . ini_get("smtp_port");echo "<br>sendmail_from: " . ini_get("sendmail_from");echo "<br>sendmail_path: " . ini_get("sendmail_path");Also, just because I'm curious, add this:echo "<br>" . php_uname() . "<br>" . PHP_OS;Finally, change this line:if (!mail($recipient, $subject, $body, "From: {$from}"))to this:if (!mail($recipient, $subject, $body, "From: {$from}\r\n"))

Link to comment
Share on other sites

OK I didn't know if I did it right, so here's my code:

<?phpini_set("display_errors", 1);error_reporting(E_ALL);$recipient = "info@takeawaydvds.com";$subject = "Online contact";$from = "webmaster@{$_SERVER['HTTP_HOST']}";echo $_SERVER['HTTP_HOST'];$redirect = "";if (isset($_POST['redirect'])){  $redirect = $_POST['redirect'];  unset($_POST['redirect']);}$body = "An online message has been received on {$_SERVER['HTTP_HOST']}";if ($_SERVER['HTTP_REFERER'] != "")  $body .= " from {$_SERVER['HTTP_REFERER']}";$body .= "\n\n";foreach ($_POST as $key => $val){  $body .= "{$key}: {$val}\n";}$body = wordwrap($body, 70);if (!mail($recipient, $subject, $body, "From: {$from}\r\n")){  echo "The email could not be sent.";  echo "<br>SMTP: " . ini_get("SMTP");  echo "<br>smtp_port: " . ini_get("smtp_port");  echo "<br>sendmail_from: " . ini_get("sendmail_from");  echo "<br>sendmail_path: " . ini_get("sendmail_path");  echo "<br>" . php_uname() . "<br>" . PHP_OS;}elseif ($redirect != "")  header("Location: {$redirect}");?>

I got a new message:buyer.takeawaydvds.comThe email could not be sent.SMTP: localhostsmtp_port: 25sendmail_from:sendmail_path: /usr/local/bin/sendmail -tLinux value.awardspace.com 2.6.13.2z1-reseller #9 SMP Sun Feb 11 21:28:54 EET 2007 i686Linux

Link to comment
Share on other sites

OK, you might need to ask awardspace about this, it looks like they have the sendmail config set up, and from what I can tell there aren't any restrictions on email there. Ask them if they are aware of anything that would cause the mail function to fail. You can copy and paste the script, or give them a link to this thread. Also, I took out all the debugging code so this is the version you can show them:

<?php$recipient = "info@takeawaydvds.com";$subject = "Online contact";$from = "webmaster@{$_SERVER['HTTP_HOST']}";$redirect = "";if (isset($_POST['redirect'])){  $redirect = $_POST['redirect'];  unset($_POST['redirect']);}$body = "An online message has been received on {$_SERVER['HTTP_HOST']}";if ($_SERVER['HTTP_REFERER'] != "")  $body .= " from {$_SERVER['HTTP_REFERER']}";$body .= "\n\n";foreach ($_POST as $key => $val){  $body .= "{$key}: {$val}\n";}$body = wordwrap($body, 70);if (!mail($recipient, $subject, $body, "From: {$from}\r\n"))  echo "The email could not be sent.";elseif ($redirect != "")  header("Location: {$redirect}");?>

Link to comment
Share on other sites

  • 2 weeks later...

OK I made it work but something's wrong with redirecting. A error comes up saying Warning: Cannot modify header information - headers already sent by (output started at /home/www/takeawaydvds.com/formmail.php:25) in /home/www/takeawaydvds.com/formmail.php on line 27

<?php$from = "From: info@takeawaydvds.com";$to = "info@takeawaydvds.com";$subject = "Default subject";if (isset($_POST['subject'])){  $subject = $_POST['subject'];  unset($_POST['subject']);}$redirect = "";if (isset($_POST['redirect'])){  $redirect = $_POST['redirect'];  unset($_POST['redirect']);}$body = "An online message has been received on {$_SERVER['HTTP_HOST']}";if ($_SERVER['HTTP_REFERER'] != "")  $body .= " from {$_SERVER['HTTP_REFERER']}";$body .= "\n\n";foreach ($_POST as $key => $val){  $body .= "{$key}: {$val}\n";}$body = wordwrap($body, 70);if(mail($to,$subject,$body,$from)){echo "<script>alert('Thank you, we will get back to you soon.')</script>";}	<<<<<<<<<line 25else{echo "<script>alert('Email NOT sent, please try again or contact us directly at info@takeawaydvds.com.')</script>";}header("location:{$redirect}");?>

It works when I take out echo but the alert doesn't show up, is there a away of using html without echo?

Link to comment
Share on other sites

You can't redirect after you use echo. It wouldn't make sense to. Redirecting means they don't even see the original page, they just get sent to a new page. So it doesn't make sense to send a message and then redirect. You would need to have the error message on the page they get redirected to, or not redirect them.

Link to comment
Share on other sites

You can't redirect after you use echo. It wouldn't make sense to. Redirecting means they don't even see the original page, they just get sent to a new page. So it doesn't make sense to send a message and then redirect. You would need to have the error message on the page they get redirected to, or not redirect them.
How would you put the message on the page that you are directed to?
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...