PHP mail question

14 posts by 2 authors in: Forums > CMS Builder
Last Post: July 13, 2010   (RSS)

By gkornbluth - July 12, 2010

Hi all,

As part of a double opt in signup process for a newsletter signup I’m trying to send an e-mail to the person filling out my modified addForm.php.

When I use a hard coded e-mail address like:

$sendto = 'me@myemail.com';

The form works flawlessly.

When I try to use:

$sendto = '$_REQUEST[‘email’]';


or

$var1 = $_REQUEST['email'];
$sendto = "$var1";

I get an Error 500: internal server error.

Any suggestions for the correct code/syntax?

Thanks,

Jerry

Here’s the working email code:

$sendto = "me@myemail.com";
$subject='Thanks for signing up.';
$header = "From: newsletter@".$_SERVER["SERVER_NAME"]."\n";
$header .= "Content-Type: text/html; charset=iso-8859-1\n";
$message = ' There is just one more step to be included on our email list.<br><br>To make sure that no one else signed you up for this list, please click on this link or paste it into your browser.<br><br> http://www.mywebpage.com';

// Send
if (mail($sendto,$subject,$message,$header, "-fwebmaster@".$_SERVER["SERVER_NAME"]))
{
echo 'Mail sent!';
} else
{
echo 'Error! Mail was not sent.';
};
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] PHP mail question

By Jason - July 12, 2010

Hi Jerry,

There's a problem with your first example:
$sendto = '$_REQUEST['email']';
What this will do is assign the value "$_REQUEST['email']" to the variable $sendto, instead of the value held in $_REQUEST['email'].

I would suggest trying this:
$sendto=$_REQUEST['email'];

You don't need to worry about putting quotes around it, as the server will automatically treat it as a string.

If this doesn't work, try putting this code in right before you try to send the email:
showme($_REQUEST);
exit;


This is some debugging code that will display all the different variables held in the $_REQUEST array. You can take a look at the email variable and see if there is anything wrong with it's format.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] PHP mail question

By gkornbluth - July 12, 2010 - edited: July 12, 2010

Jason,

Well, that did it.

I was clearing the array before the e-mail was sent.

NTB...

Thanks for the hint.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] PHP mail question

By Jason - July 12, 2010

Hi Jerry,

I think I found the problem. On line 70, you have this line:
$_REQUEST = array();

This empties the $_REQUEST array. Then on line 72, you try to assign $_REQUEST['email'] to the variable $sendto. This variable will then be blank. This would explain why it would work when you hard coded an email address. Try taking this out and see if it works then.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] PHP mail question

By gkornbluth - July 12, 2010

Hi Jason,

I just knew that I’d be contacting you again on the confirmation page.

The page, as far as I can take it is attached.

The idea is to update that record by un-hiding the record and checking the “confirmed” field.

In order to match the e-mail address to the newsletter record with the email address entered in the form so that the correct record can be updated, I’m sure there needs to at least be a change in the “where” on about line 27, but I have no idea what to put in it’s place.

I’d also rather pull the e-mail address from the received e-mail instead of having to enter it again, but that eludes me as well.

Thanks as always,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

confirmed.php 3K

Re: [gkornbluth] PHP mail question

By Jason - July 12, 2010

Hi Jerry,

It seems pretty good. The only thing I noticed is in you "WHERE" clause, you're using $CURRENT_USER['email'], which means that they need to be logged in. It also means that the email address that they enter in the form is never used except to validate that a valid email address was entered.

I'd suggest changing your SQL statement to this:

$query = "UPDATE `{$TABLE_PREFIX}newsletter` SET
hidden = '0',
confirmed = '1',
updatedDate = NOW()
WHERE email = '".mysql_escape( $_REQUEST['email'] )."'";


Other that that, are you experiencing any specific problems? Let me know.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] PHP mail question

By gkornbluth - July 12, 2010 - edited: July 13, 2010

Some day, when I grow up, I want to know what I'm doing. Just like you!

Thank you Jason.

The change works perfectly.

Is there any (easy) way that you can think of to pull the email address from the confirmation e-mail that was sent so that:

A) It doesn't have to be entered again, and

B) It can't be hacked as easily?

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] PHP mail question

By Jason - July 13, 2010

Hi Jerry,

I'm assuming that email information is being captured and processes on a page that comes before confirmation.php. If you could attach that file along with the latest version of confirmation.php, I'll take a look.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] PHP mail question

By gkornbluth - July 13, 2010 - edited: July 13, 2010

Hi Jason,

Here’s what I have:

The initial form (newsletter1.php) that creates the record and sends the confirmation e-mail.

The link in the e-mail leads to the confirmation form (confirmed.php)

Both are attached.

BTW: While you're looking, can I safely delete the second mysqlStrictMode(false); in confirmed.php on line 21?

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php