Jump to content

[SOLVED] Mail form help please.. using existing user Db


farkewie

Recommended Posts

hi i have a database table that stores all my users info like username and email address all i want to do is create something where i can create form where..

 

i have tick boxes for which users i want to send the email to including a select all and also where is enters in there name in the email so it is something like

 

" Hello  $name   Blah Blah "

 

i definatly want to beable to creat html emails. any help would be great i am still sort of new to php but am starting to understand.

 

PS: i dont want to "save" emails like a normal mailing list does im happy to create it new each time its just to say "hey the sites been updated"

Link to comment
Share on other sites

Hey, maybe this will get you started. This is what I use for one of my sites. You can alter the sql query to send to only certain people, like type = 1.

 

<?php 

global $db, $subject, $msg, $site_name, $site_email, $site_url;

$result = mysql_query("SELECT * FROM users");
while ($row = mysql_fetch_array($result)){

	$name = $row['name'];
	$email = $row['email'];
	$userid = $row['userid'];

	$message = "Hello $name,\n\n";
	$message .= "$msg\n\n\n\n";
	$message .= "-------------------------\n";
	$message .= "$site_name\n";
	$message .= "$site_url\n";

	$to = $email;
	$header = "From: $site_name <$site_email>\n";
	$header .= "Reply-To: $site_email\n\n";

	if(mail($to, $subject, $message, $header)){
		echo "Success sending to: $to (<a href=\"profile.php?userid=$userid\">$name</a>)<br>";
	}else{
		echo "<font color=\"#FF0000\">Error:</font> Failed sending to: $to (<a href=\"profile.php?userid=$userid\">$name</a>)<br>";
	}//end else
}//end while

?>

 

let me know if you have any questions.

Link to comment
Share on other sites

 

 


global $db, $subject, $msg, $site_name, $site_email, $site_url;

 

can you tell me where it gets the above values from?

 

also this looks like a background proccessing form, i really want to be able to create the html email and add images also haveing the check boxes on who to send to would be really good...

 

also when using this i get an error;

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in H:\server\xampp\htdocs\mailing_form.php on line 7

 

line 7 =

 

  while ($row = mysql_fetch_array($result)){ 

 

i have added

  include_once ("db.php"); 

Link to comment
Share on other sites

those globals were from my own script. you will have to make the DB connection. Yes this is the processor form. You will have to make the actual html form with the subject and message and whatever else you want. this will atleast get you started.

Link to comment
Share on other sites

Thanks heaps for your help.. i think im getting it now..

 

i have created a connection form..

 

db.php


<?php
class auth{
// CHANGE THESE VALUES TO REFLECT YOUR SERVER'S SETTINGS
var $HOST = "localhost";	// Change this to the proper DB HOST
var $USERNAME = "******	// Change this to the proper DB USERNAME
var $PASSWORD = "******";	// Change this to the proper DB USER PASSWORD
var $DBNAME = "*******";	// Change this to the proper DB NAME
?>

 

 

and i thought i had the proccessor form right but im still getting the same error..

 

 

mail.php



<?php

include ("db.php");
$connection = mysql_connect($dbhost, $dbusername, $dbpassword);
$db = mysql_select_db($dbname);



global $db, $subject, $msg, $site_name, $site_email, $site_url;

	$query = "SELECT * FROM signup";
	$result = mysql_query($query); 
while ($row = mysql_fetch_array($result)){

	$name = $row['fname'];
	$email = $row['email'];
	$userid = $row['uname'];
	$subject = $_POST['subject'];
	$msg = $_POST['msg'];
	$site_name = "mysite.com";
	$site_email = "site_update@mysite.com";
	$site_url = "www.mysite.com/login.php";




	$message = "Hello $name,\n\n";
	$message .= "$msg\n\n\n\n";
	$message .= "-------------------------\n";
	$message .= "$site_name\n";
	$message .= "$site_url\n";

	$to = $email;
	$header = "From: $site_name <$site_email>\n";
	$header .= "Reply-To: $site_email\n\n";

	if(mail($to, $subject, $message, $header)){
		echo "Success sending to: $to (<a href=\"members/userdetail.php?userid=$userid\">$name</a>)<br>";
	}else{
		echo "<font color=\"#FF0000\">Error:</font> Failed sending to: $to (<a href=\"members/userdetail.php?userid=$userid\">$name</a>)<br>";
	}//end else
}//end while

?>

 

 

i have also created a siple form for the subject and body which should be fine,

 

but when i press send im still getting the below error

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in H:\server\xampp\htdocs\mailing_form.php on line 14
Link to comment
Share on other sites

All working now was the connection code

 

should have been this:

 

db.php

<?php

$hostname_mail = "localhost";
$database_mail = "database";
$username_mail = "user";
$password_mail = "pass";
$mail = mysql_pconnect($hostname_mail, $username_mail, $password_mail) or trigger_error(mysql_error(),E_USER_ERROR); 
?>

[code]

thought it might help someone,

now if anyone knows how i can have so it creattes a html email with tables and linked images i would love a point inthe right direction,

would also love to know how to get my tick boxes working to select users who recieve email s.

[/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.