South Africa’s biggest forum. Discuss, discover, and connect with thousands of members.
<option value="cpt">Cape Town</option>
<option value="cy">Bellville</option>
<option value="pta">Pretoria</option>
$town = $_POST['town'];
$toEmail = $_POST['town']."@myemail.com";
I would simplify that whole thing massively, less lines of code and easier to read.
HTML:Cape Town Bellville Pretoria
Then the PHP code you would just replace the begging piece.
PHP:$town = $_POST['town']; $toEmail = $_POST['town']."@myemail.com";
I would simplify that whole thing massively, less lines of code and easier to read.
HTML:<option value="cpt">Cape Town</option> <option value="cy">Bellville</option> <option value="pta">Pretoria</option>
Then the PHP code you would just replace the begging piece.
PHP:$town = $_POST['town']; $toEmail = $_POST['town']."@myemail.com";
Lets say... Cape Town has two branches across the street of each other.... ( [email protected] [email protected] )
Let's say... If 10 people select cape town the end result should be that each received 5 emails.
The emails should be send as follows:
cpt1
cpt2
cpt1
cpt2
cpt1
cpt2
cpt1
cpt2
cpt1
cpt2
Does this make sense?
I basically want 1 locations mail to be split between two branches, 1 for you, 1 for you, etc etc.
I was thinking of putting them in an array and then use a random number between 1 and 2 to select the mail from the array, but I want to know what would be best here as I actually have no clue.
$town = $_POST['town'];
switch ($town) {
case 'capetown':
$email_address = '[email protected]';
break;
case 'bellville':
$email_address = '[email protected]';
break;
case 'pretoria':
$email_address = '[email protected]';
break;
default:
$email_address = '[email protected]';
}
mail($email_address, etc etc etc )
It is up to you to come up with the logic of which email address to send it to, I'd do something simple.
Take the current hour of the day and use modulus, if it's even send it to one address if it's odd send it to the other.
use your db, and have a field recording the last date that specific email was used.
Then, simply query the town, order by "last_date_used" ascending and choose the first result. Update db once email sent successfully.
Did you even read this?
Here's the problem. I know the logic, I have an idea but I don't know programing. I don't know what php can and cannot do and if I know I won't have an idea how to do it unless someone showed and explained it first.
FYI: I had the same idea, how to actually do it thou... nother story all together.
It is up to you to come up with the logic of which email address to send it to, I'd do something simple.
Take the current hour of the day and use modulus, if it's even send it to one address if it's odd send it to the other.
$town_branch = time();
if (($town_branch % 2) == 1){
//odd
mail(cpt1) ;
}
if (($a % 2) == 0){
//even
mail(cpt2) ;
}
Did you even read this?
$hour = (int)time("h");
if (($hour % 2)==0) {
//even
mail(cpt1) ;
} else {
//odd
mail(cpt2) ;
}
PHP:$hour = (int)time("h"); if (($hour % 2)==0) { //even mail(cpt1) ; } else { //odd mail(cpt2) ; }
Ahh cute!
Okey lets say they decide to add three new branches in the future...
Querying a db for every email sent doesn't seem like a good idea, rather use a static variable or something similar.
a DB for this is overkill.
Sure, I can understand minimising db calls. However, note:
1. A list of emails for all branches are needed.
2. The last email address used for a particular branch needs to be recorded.
The store for all of this, be it db or otherwise, can be swapped out later once a worthwhile alternative is found, but the rest of the code should work with minimal tweaking if needed. Heck, have a look at memcached (can be shared) or apc_calls (not too sure if it can be shared, but then memcached is made for this) if you loathe using a db for this.
Sure, I can understand minimising db calls. However, note:
1. A list of emails for all branches are needed.
2. The last email address used for a particular branch needs to be recorded.
The store for all of this, be it db or otherwise, can be swapped out later once a worthwhile alternative is found, but the rest of the code should work with minimal tweaking if needed. Heck, have a look at memcached (can be shared) or apc_calls (not too sure if it can be shared, but then memcached is made for this) if you loathe using a db for this.