...

View Full Version : Need help with email ()



ABA
05-04-2009, 10:22 PM
Hey guys. Im pretty knew to php and I need some help with this please!

I am trying to send out emails to customers based on a search and Im not sure how to do the email part of it. For example I would like to search for all my customers within a certain zip code and then be able to send an email to just those customers that came up in the search. I would like to somehow replace the "someone@example.com" for ALL my customers that came up in the search. Any suggestions?

<?php

$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

?>

Fumigator
05-04-2009, 10:29 PM
Do you need help with collecting all of the email addresses or help with formatting the mail() function with multiple email addresses?

ABA
05-04-2009, 10:36 PM
Hey thanks for the reply!!!:) I need help formatting it. I can exicute my email addresses on a page using the echo but I'm not sure how to send those same emails to the customers that show on my search page? That make since? Sorry I'm probably not explaining very good.

When the result page comes up with that persons info and email I would like to somehow send an email to all those results.

ABA
05-05-2009, 04:53 PM
Any suggestions!!???? Anyone? Is it even possible to do what I'm trying to do??

Killermud
05-05-2009, 04:58 PM
what is the source of these email address'? MYSQL im presuming?

ABA
05-05-2009, 05:00 PM
Yeah its MYSQL. Thats where there coming from.

Killermud
05-05-2009, 05:05 PM
Well first you need the search script but it may look like some like this :


<?

$sql="SELECT * FROM table_name"; //Add criteria if you wish
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){
$to = $rows['email'];//change to email column in MYSQL database
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
}
?>
This will send an email to everyone in that mysql result.

ABA
05-05-2009, 05:14 PM
Oh ok I kind of think I see what your saying. So Can I tie that into my regular form or how do I tie this to my search page? I REALLY REALLY appreciate your help on this!!

Killermud
05-05-2009, 05:53 PM
Yeah, whats your search script? could you post it please?

Fumigator
05-05-2009, 05:58 PM
I would recommend one email that you blind copy to all recipients.

ABA
05-05-2009, 06:10 PM
Ok Its a tone of code because I got everything else in there. Most of it you wont need. This isn't all of it but hopefully enough.

ABA
05-05-2009, 06:12 PM
[
<? /****************** START phpGoogleStoreLocator_result DIV *****************************/ ?>
<div class='phpGoogleStoreLocator_result'>
<?
$counter++;
$lat = $rows['lat'];
$lon = $rows['lon'];
$address = $rows['address'];
$city = $rows['city'];
$state = $rows['state'];
$zip = $rows['zip'];
$country = $rows['country'];
$storename = $rows['storename'];
$hours = $rows['hours'];
$url = $rows['url'];
if ($url == 'http://')
{
$url = '';
}
$image = $rows['image'];
$notes = $rows['notes'];
$phone = $rows['phone'];
$email = $rows['email'];
$id = $rows['id'];
$image_url = $rows['image_url'];
$distance = number_format($rows['distance'],2, '.', '');

?>

<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";


<? /************ START phpGoogleStoreLocator_result_location_anchor_number Div **************/ ?>
<div class='phpGoogleStoreLocator_result_location_anchor_number'>
<?echo "<a href=\"#\" onclick=\"show_marker(".$marker_id++.");\">$counter</a>";?>
</div>
<? /************ END phpGoogleStoreLocator_result_location_anchor_number Div **************/ ?>


<? /************ START phpGoogleStoreLocator_result_location_distance Div **************/ ?>
<div class=phpGoogleStoreLocator_result_location_distance>
<? echo $distance; ?>
</div>
<? /************ END phpGoogleStoreLocator_result_location_distance Div **************/ ?>


<? /************ START phpGoogleStoreLocator_result_location_image Div **************/ ?>
<div class=phpGoogleStoreLocator_result_location_image>
<?
if ($image != '' && ($image_url != '' && $image_url != 'http://'))
{
echo "<a href=\"$image_url\"><img class='phpGoogleStoreLocator_result_location_image' src=\"$image\"></a>";
}

if ($image != '' && ($image_url == '' || $image_url == 'http://'))
{
echo "<img class='phpGoogleStoreLocator_result_location_image' src=\"$image\">";
}
?>
</div>
<? /************ END phpGoogleStoreLocator_result_location_image Div **************/ ?>


<? /************ START phpGoogleStoreLocator_result_location_data Div **************/ ?>
<div class='phpGoogleStoreLocator_result_location_data'>

<? /************ START phpGoogleStoreLocator_result_location_storename Div **************/ ?>
<div class='phpGoogleStoreLocator_result_location_storename'>
<?
if ($url == '')
{
echo "$storename";
}
else
{
echo "<a href='$url'>$storename</a>";
}
?>
</div>
<? /************ END phpGoogleStoreLocator_result_location_storename Div **************/ ?>

<? /************ START phpGoogleStoreLocator_result_location_address Div **************/ ?>
<div class='phpGoogleStoreLocator_result_location_address'>
<? echo "$address"; ?>
</div>
<? /************ END phpGoogleStoreLocator_result_location_address Div **************/ ?>


<? /************ START phpGoogleStoreLocator_result_location_city Div **************/ ?>
<div class='phpGoogleStoreLocator_result_location_city'>
<? echo "$city"; ?>
</div>
<? /************ END phpGoogleStoreLocator_result_location_city Div **************/ ?>

<? /************ START phpGoogleStoreLocator_result_location_state Div **************/ ?>
<div class='phpGoogleStoreLocator_result_location_state'>
<? echo "$state"; ?>
</div>
<? /************ END phpGoogleStoreLocator_result_location_state Div **************/ ?>

<? /************ START phpGoogleStoreLocator_result_location_zip Div **************/ ?>
<div class='phpGoogleStoreLocator_result_location_zip'>
<? echo "$zip"; ?>
</div>
<? /************ END phpGoogleStoreLocator_result_location_zip Div **************/ ?>

<? /************ START phpGoogleStoreLocator_result_location_country Div **************/ ?>
<div class='phpGoogleStoreLocator_result_location_country'>
<? echo strtoupper("$country"); ?>
</div>
<? /************ END phpGoogleStoreLocator_result_location_country Div **************/ ?>





<? /************ START phpGoogleStoreLocator_result_location_map_and_directions Div **************/ ?>
<div class='phpGoogleStoreLocator_result_location_map_and_directions'>
<a href="http://maps.google.com/maps?saddr=<? echo "$_POST[address] $_POST[city] $_POST[state] $_POST[zipcode] $_POST[country]"; ?>&daddr=<?
if (use_coordinate($id, $db) == 'on')
{
echo "$lat,$lon($address, $city, $state, $zip, $country)";
}
else
{
echo "$address, $city, $state $zip $country";
}
?>&hl=en">Get Directions</a>
</div>
<? /************ END phpGoogleStoreLocator_result_location_map_and_directions Div **************/ ?>


</div>
<? /************ END phpGoogleStoreLocator_result_location_data Div (Container for address stuff)**************/ ?>


<div class="clearboth"></div>


<? /************ START phpGoogleStoreLocator_result_location_phone Div **************/ ?>
<div class='phpGoogleStoreLocator_result_location_phone'>
<? echo "<b>$phone</b>"; ?>
</div>
<? /************ START phpGoogleStoreLocator_result_location_email Div **************/ ?>
<div class='phpGoogleStoreLocator_result_location_email'>
<? echo "<b>$email</b>"; ?>
</div>
<? /************ END phpGoogleStoreLocator_result_location_email Div **************/ ?>
]

ABA
05-05-2009, 06:16 PM
I actually think I might of had it but it came up with an error because i think it needed a password to connect to my data base. Where in that code would I put a password to connect to my database? All my other stuff connects just fine. Once again Thanks again TONS for the help!

ABA
05-05-2009, 08:49 PM
I got it now! Thanks:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum