Re: PHP mail() to fetch email addresses from a database to send emails out!
| From: | olinux | Date: | Sat, 12 Apr 2003 05:12:23 +0000 |
| Subject: | Re: PHP mail() to fetch email addresses from a database to send emails out! | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27035@lists.php.net to get a copy of this message | ||
1) you need to retrieve the username from the database
before you are able to display it
so "SELECT email,username "
"while(list($email,$username)" /* i think - i dont
use list() myself */
2) you need to insert a place holder in the emails.php
file say {USERNAME} then replace it with the username
str_replace('{USERNAME}',$username,$data);
olinux
--- JeRRy <jusa_98@yahoo.com> wrote:
> Hi,
>
> After alot of reading of the PHP.net site and other
> sites I am using this code below. I'll explain the
> files the code is in and my question below:
>
> ---email.php (code to send via mail())---
>
> <?php
> $i = 0;
> mysql_connect("localhost", "usr", "pass");
> mysql_select_db("tassie_tipping");
> $query = "SELECT email FROM tipping";
> $result = mysql_query($query) or die("ERROR
> WHILE
> COLLECTING EMAIL ADDRESSES");
> while(list($email) = mysql_fetch_row($result)) {
>
> $filename = "emails.php";
> $fp = fopen($filename,"r");
> $data = fread($fp,filesize($filename));
> $data .= "<INPUT TYPE=HIDDEN VALUE=$Receiver
> NAME=WHOIS>";
> $subject = "New Email Program";
> $headers = "From:
> tipping@tassiedemononline.org.au\n";
> $headers .= "Reply-To:
> tipping@tassiedemononline.org.au\n";
> $headers .= "Organization: Tassie Demon Online
> Tipping Competition\n";
> $headers .= "Content-Type: text/html;
> charset=iso-8859-1\n";
> mail($email, $subject, $data, $headers);
> $i = $i + 1;
> }
> print("$i emails have been sent!");
> ?>
>
> ---emails.php (this is the email to be sent)---
>
> Hi blah ra....
>
> Now the code works fine but I want the following
> addition.
>
> I was the email to say:
>
> To [your name],
>
> Welcome to our site, enjoy your stay.
>
> Regards,
> Whoever
>
> How would I get the users name from the database to
> display in the email? The names would need to do a
> match with the email field somehow. Can someone
> shread some light onto this and hopefully help me on
> how I can get it to be displayed.
>
> In finishing please remember I am using 2 PHP pages,
> 1
> is the code that fetches the address and the headers
> etc and the second page is the actual email message.
>
> Would I need to add the code to page 1 or 2?
>
> Thanks for your help in advance.
>
> Jerry
>
> http://mobile.yahoo.com.au - Yahoo! Mobile
> - Check & compose your email via SMS on your Telstra
> or Vodafone mobile.
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com