Scud Posted April 18, 2008 Share Posted April 18, 2008 Hey guys; im just wondering, on our website users can submit their details and they are then sent to our mysql database where they are stored. This is all working fine and well, i now need the database to send an email to the address to user inputted when a new submission occurs. For example; a member registers, the record is added to the database and then the database sends an email back to the member confirming they registered. Also is it possible for the database to populate a email list, this way when we have to send an email out, the database just puts all the email addresses together! Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/ Share on other sites More sharing options...
madspof Posted April 18, 2008 Share Posted April 18, 2008 Well i would use this bit of code $to = $emailaddress; $subject = "You have just registered!"; $body = "Welcome to our site"; mail($to, $subject, $body) intergrate that into you registration and it should work depending if your server allows emails to be sent via php Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-520769 Share on other sites More sharing options...
Fadion Posted April 19, 2008 Share Posted April 19, 2008 As suggested, mail() will throw an email to that user, also assuming u write some headers to avoid spam and correctly show the from address. About the mailing list, u could setup a script which loops through all your users and sends an email to them, assuming u have a database field for emails. Illustration: <?php $resultsUsers = mysql_query('SELECT email FROM users'); while($valuesUsers = mysql_fetch_array($resultsUsers)){ mail($valuesUsers['email'], 'Hi', 'Mail from me'); } ?> If that's the scenario, the only problem u should care is the server load and amount of emails u can send daily. Hope that helps. Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-520890 Share on other sites More sharing options...
Scud Posted April 27, 2008 Author Share Posted April 27, 2008 in regards to the mail suggestion, which should be intergrated. how would i get it so when the email is sent it says it was sent from such and such email addres.. also how do i intergrate that, has somebody got a full code for it? Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-528206 Share on other sites More sharing options...
madspof Posted April 29, 2008 Share Posted April 29, 2008 Well post your full code and am sure i cna intergrate it for you. Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-529828 Share on other sites More sharing options...
Scud Posted May 2, 2008 Author Share Posted May 2, 2008 Below is the code, thanks in advance. <link href="stylesheet.css" rel="stylesheet" type="text/css"> <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("dbname", $con);$sql="INSERT INTO Table (Title, FirstName, LastName, Gender, Address, Suburb, State, Postcode, Country, Email, ContactNumber, ContactStatus) VALUES ('".mysql_escape_string($_POST[Title])."','".mysql_escape_string($_POST[FirstName])."','".mysql_escape_string($_POST[LastName])."','".mysql_escape_string($_POST[Gender])."','".mysql_escape_string($_POST[Address])."','".mysql_escape_string($_POST[suburb])."','".mysql_escape_string($_POST[state])."','".mysql_escape_string($_POST[Postcode])."','".mysql_escape_string($_POST[Country])."','".mysql_escape_string($_POST[Email])."','".mysql_escape_string($_POST[ContactNumber])."','".mysql_escape_string($_POST[ContactStatus])."')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "<center><font size=5 family=trebuchet MS color=#FFFFFF>You have successfully registered to our Mailing List</font></center>";mysql_close($con) ?> <br><br><center><font size = 3 family=trebuchet MS color=#FFFFFF>Redirecting within 5 seconds.</font><center> <meta http-equiv='refresh' content='5;url=http://google.com.au'> Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-531534 Share on other sites More sharing options...
madspof Posted May 2, 2008 Share Posted May 2, 2008 <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("dbname", $con);$sql="INSERT INTO Table (Title, FirstName, LastName, Gender, Address, Suburb, State, Postcode, Country, Email, ContactNumber, ContactStatus) VALUES ('".mysql_escape_string($_POST[Title])."','".mysql_escape_string($_POST[FirstName])."','".mysql_escape_string($_POST[LastName])."','".mysql_escape_string($_POST[Gender])."','".mysql_escape_string($_POST[Address])."','".mysql_escape_string($_POST[suburb])."','".mysql_escape_string($_POST[state])."','".mysql_escape_string($_POST[Postcode])."','".mysql_escape_string($_POST[Country])."','".mysql_escape_string($_POST[Email])."','".mysql_escape_string($_POST[ContactNumber])."','".mysql_escape_string($_POST[ContactStatus])."')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } $to = $_POST[Email]; $subject = "You have just registered!"; $body = "Welcome to our site"; mail($to, $subject, $body) echo "<center><font size=5 family=trebuchet MS color=#FFFFFF>You have successfully registered to our Mailing List</font></center>";mysql_close($con) ?> This code is untested and am pritty tired so it might not work anyway good look post back if it does not. Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-532070 Share on other sites More sharing options...
Fadion Posted May 3, 2008 Share Posted May 3, 2008 I rewrote your script, fixing additional problems (like no quotes in post indexes), tiding up in some places and added headers for the mail(). Didnt test is so aware of possible typos, espacially in all those post variables. <?php $con = @mysql_connect('localhost', 'username', 'password') or die('Could not connect: ' . mysql_error()); mysql_select_db('dbname'); $Title = mysql_real_escape_string($_POST['Title']); $FirstName = mysql_real_escape_string($_POST['FirstName']); $LastName = mysql_real_escape_string($_POST['LastName']); $Gender = mysql_real_escape_string($_POST['Gender']); $Address = mysql_real_escape_string($_POST['Address']); $Suburb = mysql_real_escape_string($_POST['Suburb']); $State = mysql_real_escape_string($_POST['State']); $Postcode = mysql_real_escape_string($_POST['Postcode']); $Country = mysql_real_escape_string($_POST['Country']); $Email = mysql_real_escape_string($_POST['Email']); $ContactNumber = mysql_real_escape_string($_POST['ContactNumber']); $ContactStatus = mysql_real_escape_string($_POST['ContactStatus']); $sql="INSERT INTO Table (Title, FirstName, LastName, Gender, Address, Suburb, State, Postcode, Country, Email, ContactNumber, ContactStatus) VALUES ('$Title', '$FirstName', '$LastName', '$Gender', '$Address', '$Suburb', '$State', '$Postcode', '$Country', '$Email', '$ContactNumber', '$ContactStatus')"; $results = @mysql_query($sql) or die('Query error: ' . mysql_error()); $to = $Email; $from = '[email protected]'; $subject = 'Welcome to our site'; $message = "You are now registered to mysite.com \r\n"; $message .= "Feel free to explore our site"; $headers = "From: " . $from . " \r\n"; $headers .= "Reply-To: " . $from . " \r\n"; $headers .= "Return-Path: " . $from . " \r\n"; $headers .= "X-Mailer: PHP/" . phpversion(); mail($to, $subject, $message, $headers); echo 'You have successfully registered to our Mailing List'; ?> Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-532221 Share on other sites More sharing options...
Scud Posted May 3, 2008 Author Share Posted May 3, 2008 thank you very much, much appreciated. will test it now Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-532370 Share on other sites More sharing options...
Scud Posted May 3, 2008 Author Share Posted May 3, 2008 may i asked, what is the difference between the mysql_escape_... and the mysql_real_escape. also if i wanted to set the table to encrypted fields, how do i decrypt them? Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-532373 Share on other sites More sharing options...
Fadion Posted May 3, 2008 Share Posted May 3, 2008 may i asked, what is the difference between the mysql_escape_... and the mysql_real_escape. also if i wanted to set the table to encrypted fields, how do i decrypt them? From the manual: This function will escape the unescaped_string , so that it is safe to place it in a mysql_query(). This function is deprecated. This function is identical to mysql_real_escape_string() except that mysql_real_escape_string() takes a connection handler and escapes the string according to the current character set. mysql_escape_string() does not take a connection argument and does not respect the current charset setting. U should use mysql_real_escape_string() instead of it. As for the enctypted fields, that is handled by php, not by mysql. Its called hashing and cannot be decrypted back and thats its strength. If the decryption algorithm was possible and public, it would make no sense encrypting the passwords in first place. Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-532413 Share on other sites More sharing options...
Scud Posted May 4, 2008 Author Share Posted May 4, 2008 Also is it possible to format the email being sent, in terms of centering it and so on. I have a particular email that i use at the moment, (eml file) is it possible to format the code provided above to center text, and so on? Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-532516 Share on other sites More sharing options...
Fadion Posted May 4, 2008 Share Posted May 4, 2008 U can format your email however u like using html, as long as u add these headers: $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; So from the last code i gave u, the full headers will be: $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: ' . $from . " \r\n"; $headers .= 'Reply-To: ' . $from . " \r\n"; $headers .= 'Return-Path: ' . $from . " \r\n"; $headers .= 'X-Mailer: PHP/' . phpversion(); Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-533087 Share on other sites More sharing options...
Scud Posted May 6, 2008 Author Share Posted May 6, 2008 thank you very much, much appreciated! Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-534721 Share on other sites More sharing options...
Scud Posted May 9, 2008 Author Share Posted May 9, 2008 sorry, but i havent been able to format the email. I basically want to format the text and add a few links within the text, how do i do this? Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-536645 Share on other sites More sharing options...
Fadion Posted May 9, 2008 Share Posted May 9, 2008 <?php $message = 'Welcome to my site' . "\r\n"; $message .= "<a href='http://www.mysite.com/login'>Click here to login</a>\r\n"; $message .= "This is our logo <img src='http://www.mysite.com/mylogo.jpg' />"; ?> U need more guidelines? Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-536698 Share on other sites More sharing options...
Scud Posted May 10, 2008 Author Share Posted May 10, 2008 im using the <center> brackets and for some reason it wont center the text Link to comment https://forums.phpfreaks.com/topic/101783-send-email-and-populate-email-list/#findComment-537512 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.