send email using db data

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
I have created a database which records user data (name & email). I want to delay an automated email to the user so I have been advised to use cron jobs (in cPanel). It needs to process a script but the script must specify that it can only send those emails three days after being inserted into the database. I already have a send time established in the database so I just need to check against that.

I know how to make a regular php script to send mail but am lost trying to retrieve the email address from the database to send to.

Anyone has any comments on this? thanks
 

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
Let me just add that I am now able to retrieve data from the database (with WHERE clauses also). For some reason though I cannot use this information to send mails to various entries, echoing them only works to get them to print on screen. Let me show you what I've got:

PHP:
<?php 
//Change these
$db = 'my_db';
$user = 'my_user';
$password = 'my_password';

if(!mysql_connect('localhost', $user, $password)) {
 exit(mysql_error());
}
if(!mysql_select_db($db)) exit(mysql_error());

// Get a specific result from the "example" table
$result = mysql_query("SELECT * FROM `my_table`") or die(mysql_error());  

// For multiple results
while($row = mysql_fetch_array($result)){
echo "Name: ".$row['name'];
echo "Email: ".$row['email'];
}

?>

<?php
// Create local PHP variables from the info the user gave
$email = echo .$row['email'];
 
// Strip slashes on the Local variables -disabled message field
$email = stripslashes($email);

$from = "myaccount@myhost.com";
$subject = "My Title";
//Begin HTML Email Message
$message = "This is my message";
 
echo '  ';
//end of message
$headers  = "From: $from\r\n";
$headers = "Content-type: text/html\r\n";
$to = $email;

mail($to, $subject, $message, $headers);
 
exit();
?>

This line:

PHP:
$email = echo .$row['email'];

brings back this error:

Parse error: syntax error, unexpected T_ECHO in /home/bungle/public_html/MFPOI/email_delay.php on line 26

And when I instead use this:

PHP:
$email = $row['email'];

the retrieved data is shown on screen but the email is not sent.

Can anyone kindly enlighten me as to how to make the emails send to the results of the query.

_much obliged
 
Top