blink359 Posted July 22, 2010 Share Posted July 22, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/208543-problem-with-email-script/ Share on other sites More sharing options...
blink359 Posted July 22, 2010 Author Share Posted July 22, 2010 Bump Still need help :S Quote Link to comment https://forums.phpfreaks.com/topic/208543-problem-with-email-script/#findComment-1089701 Share on other sites More sharing options...
blink359 Posted July 22, 2010 Author Share Posted July 22, 2010 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/208543-problem-with-email-script/#findComment-1089718 Share on other sites More sharing options...
TOA Posted July 22, 2010 Share Posted July 22, 2010 Instead of this: $mail = "$_POST['from']"; $result = "mysql_query("SELECT email FROM mail)"; Try this: $mail = $_POST['from']; $result = mysql_query("SELECT email FROM mail"); and that should make this line work: $to = $row['email']; Quote Link to comment https://forums.phpfreaks.com/topic/208543-problem-with-email-script/#findComment-1089728 Share on other sites More sharing options...
Pikachu2000 Posted July 22, 2010 Share Posted July 22, 2010 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()); Quote Link to comment https://forums.phpfreaks.com/topic/208543-problem-with-email-script/#findComment-1089731 Share on other sites More sharing options...
blink359 Posted July 22, 2010 Author Share Posted July 22, 2010 Thanks for that, the script should work now when i find out whats now gone wrong now, dreamweaver says its the html but the page when hosted says Parse error: syntax error, unexpected $end in /home/a9855336/public_html/massemail.php Quote Link to comment https://forums.phpfreaks.com/topic/208543-problem-with-email-script/#findComment-1089753 Share on other sites More sharing options...
Pikachu2000 Posted July 22, 2010 Share Posted July 22, 2010 Looks like it may be missing the closing curly brace }. Quote Link to comment https://forums.phpfreaks.com/topic/208543-problem-with-email-script/#findComment-1089765 Share on other sites More sharing options...
blink359 Posted July 22, 2010 Author Share Posted July 22, 2010 Yeh didnt include one after the while loop thanks, im guessing it needs to be connected to an email server of some sort to work, so any guides/recommendations? and once again thanks to everyone that helped Blink359 Quote Link to comment https://forums.phpfreaks.com/topic/208543-problem-with-email-script/#findComment-1089768 Share on other sites More sharing options...
katierosy Posted July 23, 2010 Share Posted July 23, 2010 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/208543-problem-with-email-script/#findComment-1090263 Share on other sites More sharing options...
katierosy Posted July 23, 2010 Share Posted July 23, 2010 If you will post the forms html code part along with the mytsql code part, we will be able to help. It will help us more, if you will mention which line number might have issues, means where the code fails to do the jobs it is meant to do. Quote Link to comment https://forums.phpfreaks.com/topic/208543-problem-with-email-script/#findComment-1090265 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.