Page 1 of 1

mailer form problems

Posted: Sun Sep 25, 2005 11:34 am
by dru_nasty
Well I put the following together, but when I submit the form, it just refreshes the page and doesn't show the emails the mailer was to be sent to. And it doesn't send the emails.
Anyone see anything wrong with this script?

Code: Select all

<?php
include_once('/usr/home/fss/websites/fivestarsports.net/inc/func.inc.php');
if ($_POST[op] != "send"){
//haven't seen the form, so show it
echo"
<html>
<head>
<title>Five Star Mailer</title>
</head>
<body>
<h1>Send A Newsletter</h1>
<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<p><strong>Subject:</strong><br>
<input type=\"text\" name=\"subject\" size=30></p>
<p><strong>Mail Body:</strong><br>
<textarea name=\"message\" cols=50 rows=10 wrap=virtual></textarea>
<input type=\"hidden\" name=\"op\" vallue=\"send\">
<p><input type=\"submit\" name=\"submit\" value=\"Send It\"></p>
</form>
</body>
</html>";

}else if ($_POST[op] =="send") {
//want to send form, so check for required fields
if (($_POST[subject] =="") || ($_POST[message] =="")){
header("Location: mailer.php");
exit;
}

//connect to db
$db_conn = five_connect_db();
mysql_select_db('fivestar',$db_conn);

//get emails from mailer_test table
$sql = "SELECT email FROM mailer_test";
$result = mysql_query($sql,$db_conn) or die(mysql_error());

//create a From:mailheader
$headers = "From: <webmaster@fivestarsports.com>";
//loop through results and send mail
while ($row = mysql_fetch_array($result)){
set_time_limit(0);
$email = $row['email'];
mail("$email", stripslashes($_POST[subject]),
stripslashes($_POST[message]),$headers);
echo "newsletter sent to: $email<br>";
}
}

?>

Posted: Sun Sep 25, 2005 11:41 am
by s.dot
I don't know if this is your problem.. but $_POST[op] should be $_POST['op'] or $_POST["op"].

The only case an array value shouldn't have quotes around it is if you're referencing a numerical index of the array.. such as $_POST[1].

Posted: Sun Sep 25, 2005 11:55 am
by dru_nasty
Thanks for the quick reply, but that didn't work.
I tried ' and " but no luck.
Any other ideas?

Posted: Sun Sep 25, 2005 12:06 pm
by Skara
Location should be a fully qualified URI:

Code: Select all

header('Location: http://yoursite.com/mailer.php');

Posted: Sun Sep 25, 2005 12:12 pm
by shiznatix
Skara wrote:Location should be a fully qualified URI:

Code: Select all

header('Location: http://yoursite.com/mailer.php');
not nessicarly. thats only with older browsers.

i think the problem is there is nothing in the db? that code is somewhat messy with some things that just are not nessicary. clean up the code and you might be able to find it better

Posted: Sun Sep 25, 2005 12:24 pm
by pilau

Code: Select all

if (($_POST[subject] =="") || ($_POST[message] ==""))
Should be:

Code: Select all

if (($_POST['subject'] =="") || ($_POST['message'] ==""))

Posted: Sun Sep 25, 2005 12:38 pm
by Skara
not nessicarly. thats only with older browsers.
oh. *shrugs* :P

@pilau-- that goes back to what scrotaye said.

*looks again* Aha. There are two 'l's here:
<input type=\"hidden\" name=\"op\" vallue=\"send\">

Take a look at HEREDOC syntax:
http://php.net/manual/en/language.types ... ax.heredoc

Posted: Sun Sep 25, 2005 12:49 pm
by dru_nasty
I've made the various changes you've all been helping on, but the same result.
Here is the modified code.

Code: Select all

<?php
include_once('/usr/home/fss/websites/fivestarsports.net/inc/func.inc.php');
if ($_POST['op'] != "send"){
//haven't seen the form, so show it
echo"
<html>
<head>
<title>Five Star Mailer</title>
</head>
<body>
<h1>Send A Newsletter</h1>
<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<p><strong>Subject:</strong><br>
<input type=\"text\" name=\"subject\" size=30></p>
<p><strong>Mail Body:</strong><br>
<textarea name=\"message\" cols=50 rows=10 wrap=virtual></textarea>
<input type=\"hidden\" name=\"op\" value=\"send\">
<p><input type=\"submit\" name=\"submit\" value=\"Send It\"></p>
</form>
</body>
</html>";

}else if ($_POST['op'] =="send") {
//want to send form, so check for required fields
if (($_POST['subject'] =="") || ($_POST['message'] =="")){
header("location: http://www.fivestarsports.net/mailer.php");
exit;
}

//connect to db
$db_conn = five_connect_db();
mysql_select_db('fivestar',$db_conn);

//get emails from mailer_test table
$sql = "SELECT email FROM mailer_test";
$result = mysql_query($sql,$db_conn) or die(mysql_error());

//create a From:mailheader
$headers = "From: <webmaster@fivestarsports.com>";
//loop through results and send mail
while ($row = mysql_fetch_array($result)){
set_time_limit(0);
$email = $row['email'];
mail("$email", stripslashes($_POST['subject']),
stripslashes($_POST['message']),$headers);
echo "newsletter sent to: $email<br>";
}
}

?>
Could anyone possibly test this on their server?

Posted: Sun Sep 25, 2005 12:50 pm
by pilau
Skara wrote: @pilau-- that goes back to what scrotaye said.

*looks again* Aha. There are two 'l's here:
<input type="hidden" name="op" vallue="send">
Yeah but I couldn't know if you would change these two as well.

Posted: Sun Sep 25, 2005 12:55 pm
by dru_nasty
If fixed the double l from the last piece of code.
I just tested it, and now after i click submit, the browser just keeps cycling like it's trying to send but it never does.

Posted: Sun Sep 25, 2005 12:57 pm
by pilau
Well to that we would need "/usr/home/fss/websites/fivestarsports.net/inc/func.inc.php"

Posted: Sun Sep 25, 2005 12:59 pm
by dru_nasty
weird, i got an email to go through, but the browser keeps running.
test it out here..http://www.fivestarsports.net/mailer.php

Posted: Sun Sep 25, 2005 1:44 pm
by Roja
shiznatix wrote:
Skara wrote:Location should be a fully qualified URI:

Code: Select all

header('Location: http://yoursite.com/mailer.php');
not nessicarly. thats only with older browsers.
Not true. Its a requirement for http, period. In implementation, it will actually affect NEWER browsers, not older - as older browsers are http-1.0. By old, I mean over 5 years old. Think IE4 and <NS4.4. Really old.

For newer browsers, not specifying the full URI causes problems if the user goes through a proxy, leading to the user getting the proxy address instead of the correct URI.

Location should always be a fully qualified URI.