form not submitting to MySQL list

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
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

form not submitting to MySQL list

Post by bruceg »

I am trying to set up a form which emails to a list of people who have been entered into a MYSQL database. Everything works perfect as far as being registered into the database except when I send out a sample form to members in that database (right now me), it doesn't want to send. (Don't get an email even though no errors occur and I am sent to the confirmation screen.

the code for so send to the list of emails is:

Code: Select all

<?php
// this script is used to as the action for the form on sendmailform.php
// it sends the email to all persons who have subscribed to the mailinglist and confirmed their subscription

//include the config file
include("config.php");

$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];

//Variables for the headers
// customize this stuff
$sender = "Bruce Gilbert <webguync@gmail.com>\n"; //put your name and sending address here
$reply_to = "<webguync@gmail.com>\n"; //reply-to, insert your address here,  might not be supported by your server
$return_path = "webguync@gmail.com\n"; // return-path, if you have one, also might not be supported by your server
$x_sender = "<webguync@gmail.com>\n"; //your address, another setting possibly not supported by your server

$message .= "\n\n This is a double opt-in mailing list. All recipients have confirmed their subscription. If you no longer wish to receive these emails, please go to http://$list_owner_domain_name \n
					Get this custom mailing list system for your site. Go to http://www.karlcore.com for more info! \n";

// this selects the table and orders the results by the name
// it only selects the listings that have been confirmed
$query = "
	SELECT 
		* 
	FROM 
		mailinglist 
	WHERE 
		subscribe=1 
		AND 
		confirmed=1";

$result = mysql_query($query);

while ( $row = mysql_fetch_array($result))
	{
	$rec_id = $row["rec_id"];
	$email = $row["email"];

	$recipient = $email;

	$headers = "From: $sender\r\n";
	$headers .= "Reply-To: $reply_to\r\n";
	$headers .= "Return-Path: $return_path\r\n";
	$headers .= "X-Sender: $x_sender\r\n";
	$headers .= "X-Mailer: PHP4\r\n"; //mailer
	$headers .= "X-Priority: 3\r\n"; //1 UrgentMessage, 3 Normal
	$headers .= "Mime-Version:1.0\n Content-Type: text/plain; charset=\"iso-8859-1\nContent-Transfer-Encoding: 8bit\n";
		
	mail( $recipient, $subject, stripslashes($message), $headers ); 
	sleep(1);

}

// run second query to automatically dump unsubscribed email addresses.
$query2 = "
	DELETE FROM 
		mailinglist 
	WHERE 
		subscribe='0' 
		AND 
		confirmed='0' ";

//run the query
mysql_query($query2, $link) or die (mysql_error());

mysql_close();

header("location: mailsent.php");
exit;
?>
the form can be found here:

http://www.inspired-evolution.com/sendmailform.php
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Does a simple mail test work on your server?

Code: Select all

<?php

$to      = 'you@yourdomain.com';
$subject = 'test';
$message = 'test';

mail($to, $subject, $message);

?>
Mac
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

yes, I can get emails sent using a simple form. The problem seems to be in getting the form to interact with the MySQL database and send to the email addresses listed there.

I guess that would ne this part:

Code: Select all

SELECT 
		* 
	FROM 
		mailinglist 
	WHERE 
		subscribe=1 
		AND 
		confirmed=1";

$result = mysql_query($query);

while ( $row = mysql_fetch_array($result))
	{
	$rec_id = $row["rec_id"];
	$email = $row["email"];
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

How many rows are getting returned from the database? Try:

Code: Select all

$result = mysql_query($query);
echo '<p>Query returns '.mysql_num_rows($query).' rows.</p>';
Mac
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

hey would that replace all of this

Code: Select all

$result = mysql_query($query); 

while ( $row = mysql_fetch_array($result)) 
    { 
    $rec_id = $row["rec_id"]; 
    $email = $row["email"];
or just the line with :

Code: Select all

$result = mysql_query($query);
thanks!
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

just the line $result = mysql_query($query);

:)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

using the while will loop over all of the results it finds.

just creating the associative array for the resource will only pull out one result.

if you want the email to go to mulitple addresses, use the while loop and concat the addresses to an existing string.

ex:

Code: Select all

$emaillist = "";
while($row = mysql_fetch_assoc($result))
{
  $emaillist = $row['email'].",";
}
$emaillist = substr(0,strlen($emailist)-1);
Post Reply