Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Trying to use formmail as way for people to sign up for my newsletter

Almost got it - so close - php script

9:26 pm on Sep 23, 2011 (gmt 0)

5+ Year Member

Hi, my formmail script is working great, except for 1 little problem which should probably be an easy fix, but I can't figure it out.

I need to have the email being sent from the email that people are inputting on the form.

To sign up for my newsletter, people need to email newsletter-request@mysite.com with "subscribe" in the subject, and it does that - BUT- for some reason it ends up sending it from root@web77c40.carrierzone.com. So it doesn't subcribe the email people are inputting into the form, but rather the root@web77c40.carrierzone.com email over and over.

Right now, it sends the email to the correct address, with the correct subject, but it's not sending it from the email being input into the form.

Does anyone know how to correct this?

I'm using a free formmail php script.

Here's the code:

<FORM ACTION="http://www.mysite.com/formmail.php" METHOD=POST>
<input type=hidden name="recipient" value="newsletter-request@mysite.com">
<input type=hidden name="subject" value="subscribe">
<input type=text name="email">
<input type=hidden name="redirect" value="http://www.mysite.com/newsletter/success">
<input type=hidden name="require" value="email">


<FORM METHOD="LINK" ACTION="http://www.mysite.com/formmail.php">
<INPUT TYPE="submit" VALUE="Submit">
5:16 pm on Sep 26, 2011 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

That's not the code doing this, it's in this:


Or . . . maybe you're missing some field or have named the from email field incorrectly (don't know, check the author's documentation.)

Remember, of course,that "email" and "Email" are not the same input variable.

At any rate the "from" is in the mail headers.

$headers = "From: $who_you_want_it_from\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail($who_you_want_it_to, $subject, $msg, $headers);

So whatever variable is being used to create the headers is the "from" you're looking for.
6:52 pm on Sep 26, 2011 (gmt 0)

5+ Year Member

Hi rocknbil, thanks for the reply.

I think I found the part of the formmail.php your talking about, but still not quite sure what to do.

Here is the code:

$mail_header = 'Return-Path: ' . eregi_replace($email_replace_array,'',$return_path) . $mail_newline;
if (FROM != null)
$mail_header .= 'From: ' . FROM . $mail_newline;
$mail_header .= 'Reply-to: ';

So, from the HTML code in my first post, should I be changing the "From:" part in the code above to "From:'email'" to get it to match up?

Sorry for the newbie question and thanks for your help!
4:50 pm on Sep 27, 2011 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

No . . nothing in the form will affect this, that I can tell. It's happening here:

if (FROM != null)
$mail_header .= 'From: ' . FROM . $mail_newline;

Note the unquoted word FROM. Normally this is a literal string, but the way it's presented in the code, I am guessing it is a program constant. Constants are a little different than variables in that they don't have the ability to change as the program runs, but they are a little bit like a variable in that they still hold a value.

What you are probably looking for is a line like this:

define('FROM', 'me@example.com');

it **MAY** be part of an include. If you have a line like this somewhere in the script,


This means that the file "config.php" likely has all the configuration stuff in it, so you might find where the constant is set there.

If neither are present, you can **try** adding this to the very top of the script, anywhere within a PHP delimiter:

define('FROM', 'me@example.com');

Within the script, that would/should look like

define('FROM', 'me@example.com');


So all together, combining the constant and the code, what it should output is

From: me@example.com\r\n
Reply-to: me@example.com\r\n
10:58 pm on Sep 27, 2011 (gmt 0)

5+ Year Member

I'm trying different things but it's not fixing it.

Here is the code your talking about from within formmail.php:

// To change the address the e-mail comes from use define('FROM', 'Example Name <email@example.com>');
define('FROM', null);

I changed the "null" part to 'email' and it didn't fix it.

There is also this line:

// $recipient_array format is $recipient_array = array('sometext'=>'email@example.com','asdf'=>'email2@example.com');
$recipient_array = array();

I changed the email@example.com part to 'email' and that didn't do it either.

There is no config script, it's all in the formmail.php code, so I know it's probably a simple line I've got to edit, but just not sure what, lol.
4:45 pm on Sep 28, 2011 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

There's no way that **shouldn't** work, but there is a small error there (I think.) :-) Did you quote it like the example shows? It really should be

define('FROM', '"Example Name" <email@example.com>');

Note the double quotes surrounding the name. If that doesn't work try

define('FROM', 'email@example.com');
6:55 pm on Oct 1, 2011 (gmt 0)

5+ Year Member

I give up on this script. There's many other free formmail php scripts out there, though. I'll just try and find one that works like this.

Thanks very much for all your help though rocknbil, I really do appreciate it. :)