+ Reply to Thread
Results 1 to 2 of 2

Thread: send email using db data

  1. #1
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Question send email using db data

    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

  2. #2
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Re: send email using db data

    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 Code:
    <?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 Code:
    $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 Code:
    $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

+ Reply to Thread

Similar Threads

  1. Comcast boucing email from stoli
    By karhukat in forum Free Hosting
    Replies: 1
    Last Post: 06-09-2008, 02:49 PM
  2. i can't send or recive email on my account
    By vstafford in forum Free Hosting
    Replies: 3
    Last Post: 04-18-2008, 08:39 PM
  3. Replies: 36
    Last Post: 03-28-2008, 05:10 PM
  4. imap issues on windows mail... cannot send email
    By enever in forum Free Hosting
    Replies: 6
    Last Post: 03-04-2008, 03:34 PM
  5. Example Send and Get Data from PHP in Flash.
    By satheesh in forum Tutorials
    Replies: 2
    Last Post: 12-22-2007, 09:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers