PHP - Send Multiple E-mail Messages Using Mysql Database
I am trying to send an e-mail message from a form, to each person in a MySQL database. In some cases, but not all, there are multiple e-mail address in the recordset. Each one should receive the same message addressed to them by name (FirstName and LastName) and e-mail address. I have tried "CONCAT_WS(' ', emailtest.Pri_EmailAddress, emailtest.Sec_EmailAddress, emailtest.Tri_EmailAddress) AS EmailTo" but it seems the relay account is rejecting the message if more than one address is in the EmailTo result.
Any ideas or scripts that can do this would be appreciated. Thank you in advance for your help. Similar TutorialsHi, I'm new to php and I'm trying to fill in an online form and send that info to emailaddresses with the code below, but it doesn't work AT ALL So I hope someone here could give me some guidelines to some success This is my code <?php $to = 'name@msn.com'; $subject = 'Nieuwsbrief'; // message $message = "<html>". "<head>"."<title>Nieuwsbrief</title>". "</head>"."<body>". "<center>". "<img src='http://www.xxxxxxxxxx.be/images/logo.png' style='padding: 30px 0 20px 0;' />". "</center>". "<center>". "<img src='http://www.xxxxxxxxxx.be/images/line.png' style='padding-bottom: 20px;' />". "</center>". "<h1 style='margin:10px 15px 5px 15px;font-family:Lucida Grande, Verdana, Arial, sans-serif;font-size:20px;color:#666;text-shadow:1px 1px 1px #cacaca;padding-bottom:5px;border-bottom: dotted 1px;'>". "{$_POST['txttitel']}". "</h1>". "<p>". "{$_POST['txtinhoud']}". "</p>". ."</body>"."</html>"; //get email list //open database connection $webspace='xxxxxxxxxx'; $username = "xxxxxxxxxx"; $password = "xxxxxxxxxx"; $database = "xxxxxxxxxx"; //connect to database $link=mysql_connect($webspace,$username,$password); @mysql_select_db($database) or die("<b>Unable to specified database</b>"); $query="SELECT fldemail FROM tblnieuwsbrief"; $result=mysql_query($query) or die('Error, query failed'); mysql_close($link); $row=1; $numrows=mysql_num_rows($result); $bccfield="Bcc: ". mysql_result($result,0,"fldemail"); while($row<$numrows) { $email=mysql_result($result,$row,"fldemail"); $bccfield .= "," . $email; //seperate by comma $row++; } $bccfield .= "\r\n"; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= $bccfield; // Mail it mail($to, $subject, $message, $headers); ?> thanks in advance Andreas Code: [Select] <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $dropdown = $_POST['dropdown']; $formcontent=" From: $firstname \n Surname: $lastname \n Email: $email \n Dropdown: $dropdown"; $recipient = "martin@sittingspiritually.co.uk, siobhan@sittingspiritually.co.uk"; $subject = "Newsletter Sign Up"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); if ( mail($recipient, $subject, $formcontent, $mailheader) ){ header('Location: http://www.sittingspiritually.co.uk/thankyou.php'); } else { die ("error"); } ?> I have recently created a small snippet of php code for posting mail and it's sweet apart from 1 thing. I have two email addresses in the recipient section. It only sends to the last name in the list. Is this because i have written recipient? Should it be recipients? I need this mail to be delivered to both of the email addresses. I'm sure it's simple for someone with expert knowledge. Thanks in advance for any help. Hi there, hope u guys able to help. I'm have created a enquiry form where I want these actions to run when a button is submitted: 1. Insert data from form fields into my database 2. When data is inserted into database, then send an e-mail (multiple email user) to the address with the form fields. The e-mail is carrying the form fields. so ...what I need now is how to send the form field to email. Insert the data into my table in my database,then send en e-mail. Code: [Select] <? // Connects to your Database mysql_connect("xxxxxx","xxxxxx","xxxxxx") or die(mysql_error()); mysql_select_db("xxxxxx") or die(mysql_error()); // now we insert it into the database $insert = "INSERT INTO enquiry (name, email, cont_number, subject, msg) VALUES ('".$_POST['name']."', '".$_POST['email']."', '".$_POST['cont_number']."', '".$_POST['subject']."','".$_POST['msg']."')"; $add_member = mysql_query($insert); ?> <?php function error_bool($error, $field) { if($error[$field]) { print("<td style=color:red>"); } else { print("<td>"); } } function show_form() { global $HTTP_POST_VARS, $print_again, $error; ?> <h2 align="center"> Enquiry Form</h2> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table align="center" cellpadding="3"> <tr> <?php error_bool($error, "name"); ?> Name </td> <td>:<input name="name" type="text" id="name" SIZE="33" value="<? echo $_POST["name"]; ?>"></td> </tr> <tr> <?php error_bool($error, "email"); ?> Email </td> <td>:<input name="email" type="text" id="email" SIZE="33" value="<? echo $_POST["email"]; ?>"></td> </tr> <tr><td>Contact No. </td><td> :<input type="text" name="cont_number" SIZE="33" maxlength="10"> </td></tr> <tr><td>Subject </td><td> :<input type="text" name="subject" SIZE="33" maxlength="25"> </td></tr> <tr><td>Your Message :</td><td> <textarea name="msg" cols="27" rows="5" wrap="virtual"></textarea> </td></tr> <tr> <td><th colspan=4 align="right"> <input type="reset" value="CLEAR"><input type="submit" name="Submit" value="Submit"></td> </th><td> </td> </tr> </table> </form> <? } if(isset($_POST["Submit"])) { check_form(); } else { show_form(); } function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } function check_form() { global $HTTP_POST_VARS, $error, $print_again; $error['name'] = false; if($_POST["name"]=="") { $error['name'] = true; $print_again = true; $message="The name field is empty<br>"; } if(!check_email_address($_POST['email'])) { $error['email'] = true; $print_again = true; $message.="Either Field Empty or Invalid Email ID <br>"; } if($print_again) { show_form(); } else { show_form(); $message="Thank You !! <br> Form has been submitted"; } echo "$message"; } ?> </body> </html> How do i do this? Thank you in advanced and sorry for bad English. Best regards, Desmond This will only send 1 goggles information into the database but I have a "adding" page that can actually add more than 1 goggles at once. I have no idea how to go about saving multiple goggle's information using array or loop. $name= $_POST['goggles_name']; $price = $_POST['goggles_price']; $des = $_POST['goggles_description']; $file = $_FILES['goggles_image']['name']; $chkbox = $_POST['upload']; $id = $_POST['goggles_id']; $query = "UPDATE goggles SET goggles_name = '$name' , goggles_price = '$price' ,goggles_description = '$des' WHERE goggles_id ='".$id."' "; $result = mysqli_query($link, $query) or die(mysqli_error($link)); This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=347009.0 Guys, give me an idea of using a free or open sorce software for transferring messages over a local network between computers using MAC OS and Linux platforms.
I have no idea what im doing wrong but this just isnt working, theres no error messages but im not getting any of the emails. Here is all the code that i had anything to do with editing, i have removed any personal info from it. Code: [Select] <?php $dbhost = 'localhost'; $dbuser = ' '; $dbpass = ' '; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db(" ", $conn); $result = mysql_query("SELECT ****, ********** FROM **** WHERE name='*****'"); while($row = mysql_fetch_array($result)) { $message = "<p><u><b><font size=\"5\" color=\"#800080\">********************</font></b></u></p> <p><b><font color=\"#800080\" size=\"4\">**************************************************</font></b></p> <p><b><font color=\"#800080\">*********</font></b> <b><font color=\"#333333\">**********</font></b></p> <p><b><font color=\"#800080\">********</font></b> <font color=\"#333333\"><b>***********</b></font></p> <p><font color=\"#800080\"><b>*******</b></font> <font color=\"#333333\"><a href=\"***********************************************</a></font></p> <p> </p>"; } $query=mysql_query('SELECT `email`,`name` FROM `users`'); //grab emails and names from database while($row = mysql_fetch_array($query)) //start a loop to send an email to each individual { //mail function with $row['email'] as the email address //I'm using phpmailer as an example here - - > include_once('phpMailer/class.phpmailer.php'); $mail = new PHPMailer(); // defaults to using php "mail()" $body = $message; //message inside the email $mail->From = "**************"; //email address that the email is being sent from $mail->FromName = "*************"; //more in depth for who the mail is from. $mail->Subject = "***********************************"; //The subject for the message //$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->AddAddress($row[email], $row['name']); } mysql_close($conn); ?> Let me make this clear really quick, I am not talking about this forum. Ok, so how do I set up a way that I can make a simple messaging system on my website and make it so that I can have check boxes of who I can send a message to on my website. I have a recipient field and I need to know how I can make it so that only the specific members that are checked will get the message.........does this make sense? is there a function that can send text messages using php? thru an sms modem? I have a search set up to search a table for the text entered in a textbox, I have two columns in the table, one with the first name of people, and the second with their last names, I am wondering how I can search both, so for instance: I type in the search field: Roger Smith in the database it would look like: First_name-----|-----Last_name -------------------|------------------- Roger------------|-------Smith my current query is: Code: [Select] $query = mysql_query("SELECT * FROM users WHERE fname LIKE '%$find%' OR lname LIKE '%$find%'"); But if I type both parts of the name it doesn't return anything. works fine if I just search for "Roger" OR "Smith". Hi All, I'm hoping someone can help me. I'm looking to create a form that will submit multiple entries to a MySQL database depending on the options selected on the form. I am able to submit single entries, but the multiple entire is a bit of a mystery to me. I have attached an JPG image to show an example of how I would like the form to work. I have also added the description/explination below to this example: Example 1 The form was completed and three access types were selected. Thus Three entries, all with the Same Reference number were captured into the database Example 2 The form was completed and Two Access Types were selected. Thus Two entries, all with the Same Reference number were captured into the database Example 3 The form was completed and Four Access Types were selected. Thus Four entries, all with the Same Reference number were captured into the database I'm trying to echo multiple rows from a MySQL database with no luck. I've tried this code and many other combinations with it, but can't seem to get a result. Quote $query = "select email,mens,womens from newsletters"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) {foreach ($row as .$email. .$mens. .$womens.) {echo "$email - $mens - $womens<BR>";}} What am I doing wrong? Hi Everyone, Well I have a bit of a problem... I have created a search page that I would like to return results from my MySQL database. However for some reason I can not get my page to display the results. Instead I am getting an error page. Below is the code I am using: In addition to this, should I wish for a user to be able to edit the returned results by clicking a link, how would I do that? <?php session_start(); ?> <link rel="stylesheet" type="text/css" href="css/layout.css"/> <html> <?php $record = $_POST['record']; echo "<p>Search results for: $record<br><BR>"; $host = "localhost"; $login_name = "root"; $password = "P@ssword"; //Connecting to MYSQL MySQL_connect("$host","$login_name","$password"); //Select the database we want to use mysql_select_db("schedules_2010") or die("Could not find database"); $result = mysql_query("SELECT * FROM schedule_september_2010 WHERE champ LIKE '%$record%' ") or die(mysql_error()); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row echo "<br><p>Your Schedule<BR></p><br>"; echo "<table border=1>\n"; echo "<tr> <td bgcolor=#444444 align=center><p><b>Champ</p></td> <td bgcolor=#444444 align=center><p><b>Date</p></td> <td bgcolor=#444444 align=center><p><b>Start Time</p></td> <td bgcolor=#444444 align=center><p><b>End Time</p></td> <td bgcolor=#444444 align=center><p><b>Department</p></td> <td bgcolor=#444444 align=center><p><b>First Break</p></td> <td bgcolor=#444444 align=center><p><b>Second Break</p></td> <td bgcolor=#444444 align=center><p><b>Login ID</p></td> </tr>\n"; do { printf("<tr> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> </tr>\n" , $row["champ"] , $row["date_time"] , $row["start_time"] , $row["end_time"] , $row["department"] , $row["first_break"] , $row["second_break"] , $row["login_id"] ); } while ($row = mysql_fetch_array($result)); echo "</table>\n"; } else { echo "$champ No Records Found"; } mysql_free_result($result); mysql_close($con); ?> </html> I am in the process of writing a CMS for a friend that is looking to add a classified section to his site. He will be the only one that will ever use it. I got the code to work with one image when he asked me if I could do it so he could post 6 images for each item. I am unable to figure out how to do this. I was told to do this with a while loop. This is the code that I have written so far. <?php //Check to make sure title is filled in. If not redirects to show_add.php if (!$_POST[title]) { header("Location: show_add.php"); exit; } else { //check and see if a session has started session_start(); } //if session has not been properly started redirects back to the administration menu if ($_SESSION[valid] != "yes") { header("Location: admin_menu.php"); exit; } include('includes/connection.php'); //check and see if the type of uploaded file is an image function is_valid_type($file) { $valid_types = array("image/jpg", "image/jpeg", "image/gif", "image/bmp"); if (in_array($file['type'], $valid_types)) return 1; return 0; } //Set Constants $TARGET_PATH = "/home/content/m/i/k/mikedmartiny/html/db_images/"; $title = $_POST['title']; $year = $_POST['year']; $make = $_POST['make']; $model = $_POST['model']; $descript = $_POST['descript']; $image = $_FILES['image']; //Sanitize the inputs $title = mysql_real_escape_string($title); $year = mysql_real_escape_string($year); $make = mysql_real_escape_string($make); $model = mysql_real_escape_string($model); $descript = mysql_real_escape_string($descript); $image['name'] = mysql_real_escape_string($image['name']); //$target_path full string $TARGET_PATH .= $image['name']; //make sure that all fields from form are filled in if ( $title == "" || $year == "" || $make =="" || $model == "" || $descript == "" || $image['name'] == "") { $_SESSION['error'] = "ALL FIELDS ARE REQUIRED!"; header ("Location: show_add.php"); exit; } //check to make sure it has the right file type if (!is_valid_type($image)){ $_SESSION['error'] = "You must upload a jpeg, gif, or bmp"; header ("Location: show_add.php"); exit; } //check to see if a file with that name exsists if (file_exists($TARGET_PATH)){ $_SESSION['error'] = "A FILE WITH THAT NAME ALL READY EXIST!"; header ("Location: show_add.php"); exit; } //move the image - write path to database while($image <=2) { move_uploaded_file($image['tmp_name'], $TARGET_PATH) } else { // Make sure you chmod the directory to be writeable $_SESSION['error'] = "COULD NOT UPLOAD FILE. CHECK WRITE/REWRITE PERMISSIONS ON THE FILE DIRECTORY!"; header ("Location: show_add.php"); exit; } $sql = "INSERT INTO $table (id, title, year, make, model, descript, image, image_two) VALUES ('', '$_POST[title]', '$_POST[year]', '$_POST[make]', '$_POST[model]', '$_POST[descript]', '" . $image['name'] . "', '" . $image['name'] . "')"; $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error()); ?> I only have it set up to work with 2 images right now. I thought it would be easier to get it to work properly. Then I could just add in the rest of the info later. Any help would be greatly appreciated. I'm setting up a newsletter thing for my website. I have a newsletter table in MySQL: Quote +----------------+------+--------+ | email | mens | womens | +----------------+------+--------+ | test2@test.com | 1 | 1 | | test1@test.com | 1 | 0 | +----------------+------+--------+ I am using a HTML form and this PHP code I learn't from the manual, which sends out e-mail's. PHP: if ($_POST['newsletter'] == 'Mens') { $to = ''; $subject = $_POST['subject']; $body = $_POST['body']; $header = 'From: Me Someone <me@someone.com>'; mail($to, $subject, $body, $header); } What I want to do with the above code is send out an e-mail to all the e-mails in my MySQL database that are tagged '1' under mens. How would I go about doing this? I'm guessing I will have to use a MySQL query in the $to = ''; that goes something like this: $to = '$query (select from `newsletters` where `email` = 1'); ? I understand you need to use the mail() command but this just wont work for me, my webserver is with godaddy, and they sent me an email saying that i need to use a relay server to send my mail, how do i set this up or anything? Hello, I have those code: $message = " Hello $inforow2['company']<br /> This is a notice about a pending invoice at $inforow3['company'].<br /> If you would like to see the invoice, you can see it <a href='http://$inforow3['url]'/view-invoice?id=$id.php'>here</a><br /> This is an automatic message. Replies will not be monitored.<br /> Yours faithfully<br />$inforow3['company']"; mail($inforow2['email'],"Invoice overdue #1",$message,$inforow3['sentfrom']); I'm not sure if I can send this, and it will get the values from my mysql and put it in the email or it would send the text directly, and if it ill take the html.. Can any one tell me if above code would be correct? |