Jump to content

wright67uk

Members
  • Posts

    454
  • Joined

  • Last visited

Everything posted by wright67uk

  1. Do you think that I should some how break down each of my results into seperate variables so that they are easier to work with?
  2. Hello, thankyou for your suggestion, but for some reason, this stil isnt working. I have tried; $variable = str_replace(',', '<br>', $to); and $variable = str_replace(',', "\n", $to); I have also tried placing these lines of code below... echo "<h2>Business Names:</h2>"; My code now; $code = $_GET['postcode']; $message = $_GET['message']; $shortcode = substr($code,0,2); $subject = "subject here"; $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; $number_of_results = mysql_num_rows($result); $results_counter = 0; if ($number_of_results != 0) {while ($array = mysql_fetch_array($result)) {$email = $array['email']; $results_counter++; if ($results_counter >= $number_of_results) {$to .= $email;} else {$to .= $email . ',';}}} $headers = 'From: me@me.com' . "\r\n" . 'Reply-To: me@me.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $variable = str_replace(',', '<br>', $to); // for HTML display-or- $variable = str_replace(',', "\n", $to); // to include in an email message, BUT not the email to: $message .= "\r\n". $to ; echo nl2br ($message); mail( "$to", "$subject","$message", "$headers"); echo "<br>" . "Thank you for using our mail form."; ?></body></html> In all circumstances there has been no difference in my html output or within my email. Im guessing that im puting this code in the wrong place !?!
  3. No that was it, I just want to change my email message from email1,email2,email3 to email1 email2 email3
  4. Nedal, Im sorry if I wasnt clear. I was trying to explain that on different occassions I have tried to use each of the variables mentioned seperately, within the str_replace. and that neither of the attempts made a difference to my output. Im trying to get my sql results to display in a column rather than displaying on the same line.
  5. Yep, im using my real email in the code, just changed it for forum use, to stop naughty bots. And yep im checking my junk boxes too.
  6. Hi guys, apologies for not including my code last time round. My email; Using html message - 21:11 with strng replace message on line 18 email1@yahoo.co.uk,email2@hotmail.com,email3@hotmail.co.uk My html output: <html><body><h2>Business Names:</h2>Using html message - 21:11 with str replace message on line 18<br /> email1@yahoo.co.uk,email2@hotmail.com,email3@hotmail.co.uk<br>Thank you for using our mail form.</body></html> My php code: $code = $_GET['postcode']; $message = $_GET['message']; $shortcode = substr($code,0,2); $subject = "subject here"; $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3")or die(mysql_error()); echo "<h2>Business Names:</h2>"; $number_of_results = mysql_num_rows($result); $results_counter = 0; if ($number_of_results != 0) {while ($array = mysql_fetch_array($result)) {$email = $array['email']; $results_counter++; if ($results_counter >= $number_of_results) {$to .= $email;} else {$to .= $email . ',';}}} $headers = 'From: me@me.com' . "\r\n" . 'Reply-To: me@me.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $message .= "\r\n". $to ;echo nl2br ($message); $variable = str_replace("<br>", "\r\n", $variable); mail( '$to', '$subject','$message', '$headers'); echo "<br>" . "Thank you for using our mail form."; ?></body></html> I have no error messages to give you. Where I have put $variable = str_replace("<br>", "\r\n", $variable), i have tried swapping $variable for $message, $to, Email, $row etc. etc. but with no change. I have also tried swapping the line; else {$to .= $email . ',';}}} to else {$to .= $email . "<br>";}}} and else {$to .= $email . \r\n;}}} both of which output the html how I would like it, but at the same time prevent the email from reaching me (again no error messages)
  7. I got my code to work by changing the later part of it; <html><body><?php mysql_connect("###,###,###"); mysql_select_db("treesurgery") or die("Unable to select database"); $code = $_GET['postcode']; $message = $_GET['message']; $shortcode = substr($code,0,2); $subject = "subject here"; $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; $number_of_results = mysql_num_rows($result); $results_counter = 0; if ($number_of_results != 0) {while ($array = mysql_fetch_array($result)) {$email = $array['email']; $results_counter++; if ($results_counter >= $number_of_results) {$to .= $email;} else {$to .= $email . ',';}}} $message .= "\r\n". $to ; echo nl2br ($message); echo 'Email addresses: ' . $to . '<br />'; mail( "$to", "$subject","$message"); echo "<br>" . "Thank you for using our mail form."; ?></body></html> The problem I have now is seperating each of the returned values with a new line. changing eg. value1,value2,value3 to value1 value2 value3 also, it would be great to look at your script if the offer's still open. The more I can learn the better! Thankyou.
  8. ive used str_replace but nothing changed! ive been staring at this for hours!?!?
  9. although im using nl2br, and \r\n in the code below, my results are still displaying; result1,result2,result2 opposed to result1 result2 result3 How can i change to this format? $code = $_GET['postcode']; $message = $_GET['message']; $shortcode = substr($code,0,2); $subject = "subject here"; $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; $number_of_results = mysql_num_rows($result); $results_counter = 0; if ($number_of_results != 0) {while ($array = mysql_fetch_array($result)) {$email = $array['email']; $results_counter++; if ($results_counter >= $number_of_results) {$to .= $email;} else {$to .= $email . ',';}}} $headers = 'From: me@me.com' . "\r\n" . 'Reply-To: me@me.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $message .= "\r\n". $to ; echo nl2br ($message); mail( "$to", "$subject","$message", "$headers"); echo "<br>" . "Thank you for using our mail form."; ?></body></html>
  10. The below code sends emails, to 3 recipents pulled from my sql database. Each email send successfully. What im trying to do is, display these 3 email addresses within my email message. Thats the bit that isnt working. Any ideas? <html><body> <?php mysql_connect("###,###,###"); mysql_select_db("treesurgery") or die("Unable to select database"); $code = $_GET['postcode']; $message = $_GET['message']; $shortcode = substr($code,0,2); $subject = "subject here"; $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; $number_of_results = mysql_num_rows($result); $results_counter = 0; if ($number_of_results != 0) {while ($array = mysql_fetch_array($result)) {$email = $array['email']; $results_counter++; if ($results_counter >= $number_of_results) {$to .= $email;} else {$to .= $email . ',';}}} $headers = 'From: me@me.com' . "\r\n" . 'Reply-To: me@me.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); {$message .= "\r\n". $row['email'] ;} echo nl2br ($message); mail( "$to", "$subject","$message", "$headers"); echo "<br>" . "Thank you for using our mail form."; ?></body></html></code>
  11. Thankyou very much! my code now looks like this; [code=php:0]<html><body> <?php mysql_connect("*","*","*"); mysql_select_db("*") or die("Unable to select database"); $code = $_GET['postcode']; $message = $_GET['message']; $shortcode = substr($code,0,2); $subject = "subject here"; $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; $number_of_results = mysql_num_rows($result); $results_counter = 0; if ($number_of_results != 0) {while ($array = mysql_fetch_array($result)) {$email = $array['email']; $results_counter++; if ($results_counter >= $number_of_results) {$to .= $email;} else {$to .= $email . ',';}}} $headers = 'From: me@me.com' . "\r\n" . 'Reply-To: me@me.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); {$message .= "\r\n". $row['email'] ;} echo nl2br ($message); mail( "$to", "$subject","$message", "$headers"); echo "<br>" . "Thank you for using our mail form."; ?></body></html> This is great as it send an email to each of the returned sql values. I have somehow caused my message not to display the returned values though? I used to click submit on my form and get a list of email addresses ive just emailed. (this list would appear in my sent email too.) do you know the best way to factor that in? I thought where I put [syntax=php]{$message .= "\r\n". $row['email'] ;} echo nl2br ($message);[syntax=php][/syntax] would display my values for users to see? Many thanks by the way.
  12. Im having a little trouble with the script below. I get my three sql values returned fine, without a problem. The problem is that Im not sending any emails with it. Wether this is a problem with my syntax, headers, code ??? i dont know. Please go easy on my scripts, im a learning newbie. <html><body> <?php mysql_connect("***","***","***"); mysql_select_db("***") or die("Unable to select database"); $code = $_GET['postcode']; $message = $_GET['message']; $shortcode = substr($code,0,2); $subject = "subject here"; $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; while($row = mysql_fetch_assoc($result)) {$message .= "\r\n". $row['email'] ;} {$value = $row['email'].',';} rtrim($row, ','); $i = 0; {$i++; switch($i) {case 0:$value1 = $row['email']; break; case 1:$value2 =$row['email']; break; case 2:$value3 =$row['email']; break; }} $to = "$value1, $value2, $value3"; echo nl2br ($message); $headers = 'From: me@me.com' . "\r\n" . 'Reply-To: me@me.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail( "$to", "$subject","$message", "$headers"); echo "<br>" . "Thank you for using our mail form."; ?></body></html>
  13. Thankyou for the replys. Ive tried too put this together, and i still get the correct html returned, but unfortunately no emails are sent. Have I put this together wrong? $code = $_GET['postcode']; $message = $_GET['message']; $emailad = "email@email.comuk"; $shortcode = substr($code,0,2); $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; while ($row = mysql_fetch_array( $result )) { $message .= "\r\n". $row['email'] ; } $i = 0; while($row = mysql_fetch_assoc($result)) {$value[] = $row['Email'];} { $i++; switch($i) { case 0:$value1 = $row['Email']; break; case 1:$value2 =$row['Email']; break; case 2:$value3 =$row['Email']; break; }} echo nl2br ($message); mail( "$value1, $value2, $value3", "Header","$message" ); echo "<br>" . "Thank you for using our mail form.";
  14. This is because the returned values are email addresses and i would like to put the individual variables into my mail string. eg. mail( "$value1, $value2, $value3", "Header","$message" );
  15. How can i put returned values from an sql query, into variables. If the returned values from a query were; email1@com, email2@com, email3@com how would i go about puting them into variables? $value1 = (1st returned value from my sql query, in this case it would be email1@com) $value2 = (2nd returned value from my sql query, in this case it would be email2@com) $value3 = (3rd returned value from my sql query, in this case it would be email3@com) $code = $_GET['postcode']; $message = $_GET['message']; $emailad = "email@email.comuk"; $shortcode = substr($code,0,2); $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; while ($row = mysql_fetch_array( $result )) { $message .= "\r\n". $row['email'] ; } echo nl2br ($message); mail( "$emailad", "Header","$message" ); echo "<br>" . "Thank you for using our mail form."; ?> </body> </html> Thankyou for any ideas, or suggestions.
  16. How can i put returned values from an sql query, into variables. If the returned values from a query were; email1@com, email2@com, email3@com how would i go about puting them into variables? $value1 = (1st returned value from my sql query, in this case it would be email1@com) $value2 = (2nd returned value from my sql query, in this case it would be email2@com) $value3 = (3rd returned value from my sql query, in this case it would be email3@com) $code = $_GET['postcode']; $message = $_GET['message']; $emailad = "email@email.comuk"; $shortcode = substr($code,0,2); $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; while ($row = mysql_fetch_array( $result )) { $message .= "\r\n". $row['email'] ; } echo nl2br ($message); mail( "$emailad", "Header","$message" ); echo "<br>" . "Thank you for using our mail form."; ?> </body> </html> Thankyou for any ideas, or suggestions.
  17. changing; echo $message; to echo nl2br $message; seemed to clear this one up
  18. The only thing with that is that instead of <br> following each row in my email, it would be <p> instead
  19. The code below returns the correct results, which are in this case are email addresses. After each displayed value there is a br eg. emai1@hotmail.com<br>email2@hotmail.com<br>email3@ etc. So the quesion is, can i change the below codeing to prevent this. I have tried changing $message .= "<br>". $row['email'] to $message .= "\n". $row['email'] but this results in; Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html so now i changed the line to $message .= "\r\n". $row['email'] and my email displays perfectly. The only problem now is that the email addresses and message are all on one line on screen, is there a way to get each of the returned email addresses to sit on a new line, without it bringing back those br br br's in my email output? mysql_select_db("treesurgery") or die("Unable to select database"); $code = $_GET['postcode']; $message = $_GET['message']; $emailad = "email@hotmail.co.uk"; $shortcode = substr($code,0,2); $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; while ($row = mysql_fetch_array( $result )) { $message .= "\r\n". $row['email'] ; } echo $message; mail( "$emailad", "Header","$message" ); echo "<br>" . "Thank you for using our mail form."; Thankyou
  20. The code below returns the correct results, which are in this case are email addresses. After each displayed value there is a br eg. emai1@hotmail.com<br>email2@hotmail.com<br>email3@ etc. So the quesion is, can i change the below codeing to prevent this. I have tried changing $message .= "<br>". $row['email'] to $message .= "\n". $row['email'] but this results in; Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html $code = $_GET['postcode']; $message = $_GET['message']; $emailad = "email@hotmail.co.uk"; $shortcode = substr($code,0,2); $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; while ($row = mysql_fetch_array( $result )) { $message .= "<br>". $row['email'] ; } echo "\n"; echo $message; mail( "$emailad", "Header","$message" ); echo "<br>" . "Thank you for using our mail form.";
  21. Im a newbie trying to get my head around php and sql, please can anyone help me with a statement, or point me to a place where I can find out? - have tried w3schools. How can I get my like statement to only compare the first two charracters of a value? Let's say $code = EN7 6PX (user has typed this into a html form) for eg . SELECT email FROM treesurgeons WHERE postcode LIKE '%$code%' How can I tell my like statement to only take notice of the first two charracters of the post code (in this case 'EN')? So that I get returned EN4 1PP, EN5 6RT, EN7 3OL etc.
  22. Im a newbie trying to get my head around php and sql, please can anyone help me with a statement, or point me to a place where I can find out? - have tried w3schools. How can I get my like statement to only compare the first two charracters of a value? Let's say $code = EN7 6PX (user has typed this into a html form) for eg . SELECT email FROM treesurgeons WHERE postcode LIKE '%$code%' How can I tell my like statement to only take notice of the first two charracters of the post code (in this case 'EN')? So that I get returned EN4 1PP, EN5 6RT, EN7 3OL etc.
  23. How can i embed variables into an email message. Eg. If i want to add the result of mysql query, would i do somthing similiar to this; mail( "email@domain.co.uk", "Header","$message $result" ); ? Obviously this doesn't work. In fact i get the message from my html form, followed by 'Resource id #2'. Im learning php at the moment. If anyone could help me with this, or point me in the right direction this would be great. Iv'e looked at w3schools but I cant find anything specific like this. mysql_connect("db.hostedresource.com","treesurgery","password here"); mysql_select_db("treesurgery") or die("Unable to select database"); $code = $_GET['postcode']; $message = $_GET['message']; $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode LIKE '%$code%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; while ($row = mysql_fetch_array( $result )) { echo " ".$row['email'] . "<br>"; } echo "<br>"; echo $message; mail( "email@domain.co.uk", "Header","$message" ); echo "Thank you for using our mail form.";
  24. Thankyou for getting back to me. I did as you said, and im perhaps another step forward, as it seems as if mysql query is being processes. I do however now get a response of ; Unknown column 'yes' in 'where clause' Does this mean that for some reason that the value for `$code` is being totally ignored, leaving 'yes' to be the column name opposed to being a value? heres my browser url eg. If i type EN into my html form; http://www.mydomainhere.co.uk/phponlyform.php?postcode=EN&Submit=Submit+Query Many thanks
  25. the actual database would be somthing like this; phone number / company name / SG / EN / CM / SW / NE / SE 0800 089098 / Company A / YES / NO / YES / YES / YES / YES 0800 111111 / Company B / NO / YES / NO / YES / NO / YES 0800 222222 / Company C / YES / NO / NO / NO / NO / NO 0800 333333 / Company D / NO / NO / NO / NO / NO / NO 0800 444444 / Company E / YES / YES / NO / NO / YES / YES I have it like this, as the companies will subscribe to different postcode areas. This is why for example in my html form the user typed in EN, I would want the phone numbers of company b and company e displayed. Im i right in thinking that I would have to change the values of YES and NO to another word such as "subscribes" and "no subscription"?
×
×
  • 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.