mailer form problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

mailer form problems

Post 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>";
}
}

?>
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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].
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

Post by dru_nasty »

Thanks for the quick reply, but that didn't work.
I tried ' and " but no luck.
Any other ideas?
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Location should be a fully qualified URI:

Code: Select all

header('Location: http://yoursite.com/mailer.php');
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

Code: Select all

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

Code: Select all

if (($_POST['subject'] =="") || ($_POST['message'] ==""))
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

Post 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?
Last edited by dru_nasty on Sun Sep 25, 2005 12:53 pm, edited 1 time in total.
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post 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.
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

Post 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.
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

Well to that we would need "/usr/home/fss/websites/fivestarsports.net/inc/func.inc.php"
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

Post 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
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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.
Post Reply