homepage Welcome to WebmasterWorld Guest from 54.198.140.182
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Trying to use formmail as way for people to sign up for my newsletter
Almost got it - so close - php script
anon123




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

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">

<br><br>

<FORM METHOD="LINK" ACTION="http://www.mysite.com/formmail.php">
<INPUT TYPE="submit" VALUE="Submit">
</FORM>

 

rocknbil




msg:4367440
 5:16 pm on Sep 26, 2011 (gmt 0)

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

formmail.php

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.

anon123




msg:4367474
 6:52 pm on Sep 26, 2011 (gmt 0)

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!

rocknbil




msg:4367878
 4:50 pm on Sep 27, 2011 (gmt 0)

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,

include('config.php');

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

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

// OTHER PHP CODE HERE
?>

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

anon123




msg:4368022
 10:58 pm on Sep 27, 2011 (gmt 0)

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.

rocknbil




msg:4368351
 4:45 pm on Sep 28, 2011 (gmt 0)

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');

anon123




msg:4369578
 6:55 pm on Oct 1, 2011 (gmt 0)

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. :)

Cheers.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved