Jump to content

Pulling data into sendmail


joshuaer

Recommended Posts

Hello I am fairly new to PHP and MySql and have started working on a small test site that has a basic login that creates a user, forwards them to a member page and on that member page has a field for inputting their cell phone number and another drop down that allows them to chose what cell carrier they have. This works well and caputures the data correctly, but what I am trying to do is creat a sendmail script that pulls the data from the two different colums and places them both into the bcc of the sendmail to send a mms text to the user. I can manually put in the information and the sendmail will send it out correctly but I cannot seem to figure out how to pull it from mysql Two columns CellNumber - - - CellAddress 1112223333 @txt.att.net thank you for any help or suggestions

Link to comment
Share on other sites

$row=1;This is code I was working from that I found from a sendmail tutorial page $numrows=mysql_num_rows($result);$bccfield="Bcc: ". mysql_result($result,0,"email");while($row<$numrows){$email=mysql_result($result,$row,"email");$bccfield .= "," . $email;$row++;}$bccfield .= "\r\n";

Link to comment
Share on other sites

So if this contains the value of one field: mysql_result($result,$row,"email") then you need to join it with the value in another field, so join it with the same mysql_result call except a different name for the field instead of email. You can use the concatenation operator to join the two values: http://www.w3schools.com/php/php_string.asp

Link to comment
Share on other sites

can you tell me what I am doing wrong with this? I can manually put the email address in the $to = and it will send just fine but if I put the $Cnumber."".$address in there it is not working. <?phpmysql_connect("", "", "") or die(mysql_error());mysql_select_db("") or die(mysql_error());$headers = from;$result = mysql_query("SELECT * FROM users")or die(mysql_error());$Cnumber = mysql_result($result,$row,"Cnumber");$address = mysql_result($result,$row,"address");if(mysql_num_rows($result) > 0){$message = 'hello';$count = 0;while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)){$to .= $Cnumber."".$address;mail($to, $headers, $message);$count++;}echo "myResult=$count Emails Sent. Done.";echo $to;}else{echo "myResult=Email Submissions Failed.";}?>

Link to comment
Share on other sites

You should print out the $to variable when you're sending the email to validate it, it looks like it is a string of more than one address bunched together. Each time through the loop you're adding another address to it, even though it looks like the same address.

Link to comment
Share on other sites

Guest So Called

When you get that script working it looks like it would be pretty useful for spamming. I guess it's lucky you're only sending them to your members.

Link to comment
Share on other sites

You should enable reporting of all errors, add this to the top: ini_set('display_errors', 1);error_reporting(E_ALL); You'll find that in these lines: $Cnumber = mysql_result($result,$row,"Cnumber");$address = mysql_result($result,$row,"address"); that the variable $row is not defined. In this line: $to .= $Cnumber."".$address; You don't want to keep adding new addresses to the existing list, you only want to send to 1 address at a time. So replace that line with this: $to = $row['Cnumber'] . $row['address'];

Link to comment
Share on other sites

Thank you so much that worked, the error report returned this Notice: Undefined variable: row in /on line 12Notice: Undefined variable: row in /on line 13 those two lines are $Cnumber = mysql_result($result,$row,"Cnumber");$address = mysql_result($result,$row,"address"); but everything worked how it should have, it pulled the two columns, combined them and sent the email to the combined information

Link to comment
Share on other sites

Guest So Called

Well for one thing you haven't defined $row before those lines in your script, e.g. "$row = 1;" In fact I can't see those lines even do anything for you. I would use $result = mysql_query() to get all the rows, and then $row = mysql_fetch_assoc($result) in a while loop to get each row and process them one at a time.

Edited by So Called
Link to comment
Share on other sites

Guest So Called

Note that I modified my post while you added your reply, so you may have not seen my modified reply.

Link to comment
Share on other sites

with this code I also need to have it look at the dates stored in the database and send the data on the days that are in the rows for the users. This is what I have but I am not sure how to make it send out on the days. I have the days in the database as mon,tue,wed,etc Thanks

Link to comment
Share on other sites

is the date stored only the day names as string? it cant recognize any particular day. either you store as a date data type or better will be timestamp.

Link to comment
Share on other sites

Guest So Called

Run it every day and do calculations based on your local time, the server's local time, or the member's local time, resolve that into the local day of week, and then execute your response based upon that. Run your script only once per day, at a time convenient to you or to your server.

Link to comment
Share on other sites

Guest So Called
is the date stored only the day names as string? it cant recognize any particular day. either you store as a date data type or better will be timestamp.
I use Unix date for all my date time stuff. I sometimes wonder if I've stumbled upon some sort of truism. I never have the problems I've seen in these forums. Unix time is # seconds since Jan 1 1970 UTC. There is never any ambiguity in that. Good morning/day/afternoon/evening/night, it's 1340678891 Unix time! ###### a doodle doo! :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...