Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Mail function->sending mail using Mailaddress from database

the mail() function

Moderators: macek, egami, gesf

Mail function->sending mail using Mailaddress from database

Postby novunimic » Thu Apr 05, 2012 10:00 am

Hello my fellow php enthusiasts,

The script I'm trying to create involves sending an email to a person's email address which is stored within a database.
I have unit-tested the modules establishing the SQL connection, getting a result set in an array, sending an echo to the web page with the result set and of course sending mail using the Mail function.
All three work like a charm when separated, when put together and with the variables used in the mail function it doesn't sent an email whatsoever.

To make the coding more easier, it doesn't need any user-input. A cron-job will do the job starting up the php page via lynx.

Thanks in advance,

Greets, Novunimic

Code: Select all
<?php
$con = mysql_connect("localhost","user","password");

if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);

$result = mysql_query("SELECT Emailaddress FROM table where Firstname = Name");

while($row = mysql_fetch_array($result))
{
mail($result['Emailaddress'],'subject','text');
}

mysql_close($con);

?>
novunimic
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Apr 05, 2012 9:40 am

Re: Mail function->sending mail using Mailaddress from datab

Postby novunimic » Mon Apr 30, 2012 9:31 pm

This issue has been solved.

Seems it was quite obvious. Placing the variables to be used in the mail function within the While loop was step one. The last step was to place the variable $row within the before mentioned variables. Example is
Code: Select all
$to = $row['Emailaddress'];
.
novunimic
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Apr 05, 2012 9:40 am


Return to PHP coding => Mail

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.