Jump to content

Problem with email script


blink359

Recommended Posts

I want to be able to send emails to multiple people stored in a database i tried to use some code that should work and it doesnt, i have a piece of code that allows information to go into the database which is

THIS ONE WORKS:

[<?php
mysql_connect("mysql12.000webhost.com","a9855336_root","n4th4n");
mysql_select_db("a9855336_mail");

if(!$_POST['name'] . !$_POST['email'] . !$_POST['password'])
{ 
	die("Please fill in all required fields.");
}
if(!$_POST['name'])
{ 
	die("Please enter your Name.");
}
if(!$_POST['email']) 
{
	die("Please enter your Email.");
}
if(!$_POST['password']) 
{
	die("Please enter your Password.");
}
if(strlen($_POST['password']) < 6)
{
	die("Your password must be more than 6 characters in legnth");
}
if(strlen($_POST['password']) > 20)
{
	die("Your password must be less than 20 characters in legnth");
}
mysql_query("INSERT INTO mail   (name, email, password) VALUES('{$_POST['name']}', '{$_POST['email']}', '{$_POST['password']}' ) ") 
or die(mysql_error());  

echo "Email Address Added";

mysql_close
?>

But my code to send the emails did not work as it was giving errors such as

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a9855336/public_html/massemail.php it says this on loads of different lines

THIS ONE DOESN'T WORK:

<?php
mysql_connect("mysql12.***********com","a9****6_root","*******");
mysql_select_db("a9855336_mail");

$mail = "$_POST['from']";
$result = "mysql_query("SELECT email FROM mail)";

while ($row = mysql_fetch_array($result))  
{ 
$to = $row['email'];

$subject = $_POST['subject'];
$message = $_POST['message'];
$from = "[email protected]";
mail('$to', '$subject', '$message', null,
   '-$from');

?>

My database structure is

DB name: a9855336_mail

Table name is mail

the row i want is Email

If anyone can help me fix the script or help me write a better one or show me a website that has a guide/script that does exactly this please tell me.

 

Thanks

 

Blink359

Link to comment
https://forums.phpfreaks.com/topic/208543-problem-with-email-script/
Share on other sites

Found the lines that have problems just dont know whats wrong there marked below

<?php
mysql_connect("mysql12.********.com","a9855336_*******","********");
mysql_select_db("a9855336_mail");

THIS LINE$mail = "$_POST['from']";
THIS LINE$result = "mysql_query("SELECT email FROM mail)";

while ($row = mysql_fetch_array($result))  
{ 
THIS LINE$to = $row['email'];

$subject = $_POST['subject'];
$message = $_POST['message'];
THIS LINE $from = "[email protected]";
mail('$to', '$subject', '$message', null,
   '-$from');

?>

The quoting was wrong in the mysql_query() execution, but you should get in the habit of keeping the query string separate from the query execution. It makes debugging much easier, since you can echo the query string if needed.

 

$query = "SELECT email FROM mail";
$result = mysql_query($query) or die('This query string: ' . $query . '<br />Returned this error: ' . mysql_error());

It will be good if you just use print_r($array) to see the structure of array and change the array structure as required in your case.

 

<?php

$str1['x']=5;

$str1['y']=6;

$str[]=$str1;

 

$str1['x']=1;

$str1['y']=2;

$str[]=$str1;

 

 

$str1['x']=4;

$str1['y']=3;

$str[]=$str1;

 

$str1['x']=8;

$str1['y']=2;

$str[]=$str1;

 

print_r($str);

 

foreach($str as $row){

    $m[$key]  = $row['x'];

    $n[$key] = $row['y'];

    $x[]= $row

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.