Page 1 of 1
Email based on nicknames???
Posted: Wed Sep 24, 2003 2:27 pm
by wesnoel
Ok what I have is a form that when submitted looks at an initials field and send the contents to an email associated to that persons initials.
I have the form built.
The email addresses are listed in a flat file as such:
JPS
john@host.com
WFN
wes@host.com
etc.....
Where do I begin?
Posted: Wed Sep 24, 2003 2:32 pm
by Leviathan
1) Read the file into an associative array, where each entry has two elements: initials and e-mail.
2) Take the set of initials that you have.
3) Loop through the array. When you find a match between your input initials and the initials field, get the e-mail field, and use sendmail to send the e-mail.
Posted: Wed Sep 24, 2003 3:45 pm
by wesnoel
Ok that makes sence.
But...
I am very new to PHP and I might need a little bit of a better pointer.
I'm not looking for a full handout of code but maybe some sample to get me started in the right direction.
Wes/
Posted: Wed Sep 24, 2003 4:30 pm
by evilMind
Code: Select all
<?php
/* I've skipped the reading in of the file which has the email addresses in it and just set a static array */
$inputEmailAddress = $_REQUESTї'you_selected_this'];
/* You'll want to change this to read the values in from a file */
$myEmailAbbrs = array( 'JPS'=>'john@host.com' , 'WFN'=>'wes@host.com');
foreach ( $myEmailAbbrs AS $key => $value ) {
// Split the array into pieces the $key and the $key's $value
// Then Check to see if the inputEmail that was passed in matches one of the key's in the array
if ( $inputEmailAddress == $key ) {
// you found a match? Set the realEmail and break out of the loop
$realEmail = $myEmailAbbrsї$key];
break;
}
}
if ( !empty( $realEmail ) ) {
// Did we find a match above?
// Yeah, so mail $realEmail and send to a thankie page or something
mail($realEmail , 'Subject' , 'Message' );
header( 'Location: EmailConfPage.php');
exit();
} else {
// Didn't find a email , error out...
header( 'Location: somethingMessedUpPage.php');
exit();
}
?>
Is what I believe Leviathan is talking about...
Posted: Wed Sep 24, 2003 4:49 pm
by wesnoel
Thanks Evil...
Let me hack through that for a bit.
I'll let you know how it turned out.
Posted: Wed Sep 24, 2003 5:08 pm
by Leviathan
Indeed, that's what I meant. I'm the kind of person who won't write a lot of code first until I know the person really needs it. Sorry if I seemed cryptic Wes, and good luck learning

Posted: Wed Sep 24, 2003 6:00 pm
by wesnoel
Oh no problem Leviathan
Thank you for puting it out there for me to learn.
I think It might work out.
I'll keep you posted
Posted: Wed Sep 24, 2003 6:09 pm
by McGruff
You'd get problems with duplicate initials if there are a large number of users.
Valid initials could also be guessed pretty easily making this insecure without additional checks.
None of that would be relevant if you're just working on a test script.
Posted: Wed Sep 24, 2003 6:35 pm
by wesnoel
Actually it is for an in-office tracking system. only a few admin will have access to the page sending emails. I'm not to worried about it.
Posted: Wed Sep 24, 2003 6:48 pm
by Cruzado_Mainfrm
when you do these kind of executions it's better to change the time out to something longer, by default is 300ms=30seconds
Posted: Thu Sep 25, 2003 4:44 pm
by wesnoel
OK I have tried to get this to work but to no avail.
Anyone willing to help out?

Posted: Fri Sep 26, 2003 3:49 am
by twigletmac
Could where you've gotten to with the code?
Mac
Posted: Fri Sep 26, 2003 5:31 pm
by wesnoel
OK I have figured The nikcnames part and the sending mail part. I can even add a template to make it all look nice and pretty. The code below is all working fine .....
This is where I find the email address based on the nickname value passed from the form.
Code: Select all
<?php
// File Path
$CSVfile = "email_list.csv";
//data from form
$initials = $_POST['initials'];
// Default email address
$email = "fail@noone.com";
/// Retrieve name form information
$initials = ereg_replace("/","",$initials);
$initials = strtolower($initials);
// Open the file, and retrieve the contents
$fp = fopen($CSVfile,"r");
while ($data = fgetcsv($fp,500,",")){
if ($initials == strtolower($data[0])){
$email = trim(strtolower($data[1]));
break;
}
}
//Close csv file
fclose($fp);
?>
...and this is the part that sends the templated email...
Code: Select all
<?php
$recipient = "$email";
$subject = "Blue Slip Verrification";
$template = "blue_slip_template.php";
$fcontents = fopen( $template, "r" );
$message = fread( $fcontents, filesize( $template ) );
fclose ( $fcontents );
clearstatcache();
// Declare Headers
$headers = "From: BlueSlip ";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$formattedMSG = htmlentities($message);
mail($recipient, $subject, $message, $headers);
?>
Most of this is just made up of script I have found on this forum.
All of that works fine. The only thing I cant get to work is getting all of the varibles into the template before it sends.
Any one know how to do this?
The template is structured like so.
Code: Select all
<head>
<STYLE>
body {
margin: 10pt;
color: #003366;
font-family: arial;
font-size: 9px;
}
.test {
font-family: verdana;
color: #DC143C;
font-size: 11px;
}
.edit {
border: 1px dashed #003366;
font-size: 11px;
}
}
</STYLE>
</head>
<body>
<table border="1" color= "#003366" cellpadding="6" cellspacing="0" bgcolor="#000000" >
<tr height="19">
<td valign="top" bgcolor="white" height="19"class="edit"><b><font color="#003366">Service Provider:</font></b><font size="3"><b> $fn</b></font></td>
</tr>
<tr>
<td bgcolor="white" class="edit">
<table border="0" cellspacing="5" cellpadding="0" bgcolor="white" class="edit">
<tr>
<td valign="bottom" bgcolor="white" width="132"><b><font size="2" color="#003366">MID#</font></b></td>
<td align="left" valign="bottom" bgcolor="white" width="156"><b><font size="2" color="#003366">Date</font></b></td>
<td valign="bottom" bgcolor="white" width="85"><font size="2" color="#003366"><b>Initials</b></font></td>
<td valign="bottom" bgcolor="white" width="13"></td>
<td valign="bottom" bgcolor="white"><b><font size="2" color="#003366">Supplies</font></b></td>
<td align="center" valign="bottom" bgcolor="white" width="50"><b><font size="2" color="#003366">QTY</font></b></td>
</tr>
<tr>
<td bgcolor="white" width="132" class="test"> $mid </td>
<td align="left" bgcolor="white" width="156" class="test">$date</td>
<td bgcolor="white" width="85" class="test">$initials</td>
<td bgcolor="white" width="13" class="test"><font size="2">1.</font></td>
<td nowrap bgcolor="white" class="test">$sup1</td>
<td align="center" bgcolor="white" width="50" class="test">$qty1</td>
</tr>
<tr>
<td colspan="3" valign="bottom" bgcolor="white" width="383"><font size="2" color="#003366"><b>Business Name</b></font></td>
<td bgcolor="white" width="13"><font size="2">2</font></td>
<td nowrap bgcolor="white" class="test">$sup2</td>
<td align="center" bgcolor="white" width="50" class="test">$qty2</td>
</tr>
<tr>
<td colspan="3" bgcolor="white" width="383"class="test">$businessname</td>
<td bgcolor="white" width="13"><font size="2">3.</font></td>
<td nowrap bgcolor="white" class="test">$sup3</td>
<td align="center" bgcolor="white" width="50" class="test">$qty3</td>
</tr>
<tr>
<td colspan="3" valign="bottom" bgcolor="white" width="383"><font size="2" color="#003366"><b>Address</b></font></td>
<td bgcolor="white" width="13"><font size="2">4.</font></td>
<td nowrap bgcolor="white" class="test">$sup4</td>
<td align="center" bgcolor="white" width="50" class="test">$qty4</td>
</tr>
<tr>
<td colspan="3" bgcolor="white" width="383" class="test">$address</td>
<td bgcolor="white" width="13"><font size="2">5.</font></td>
<td nowrap bgcolor="white" class="test">$sup5</td>
<td align="center" bgcolor="white" width="50" class="test">$qty5</td>
</tr>
<tr>
<td valign="bottom" bgcolor="white" width="132"><b><font size="2" color="#003366">City</font></b></td>
<td valign="bottom" bgcolor="white" width="156"><b><font size="2" color="#003366">State</font></b></td>
<td valign="bottom" bgcolor="white" width="85"><b><font size="2" color="#003366">Zip</font></b></td>
<td bgcolor="white" width="13"><font size="2">6.</font></td>
<td nowrap bgcolor="white" class="test">$sup6</td>
<td align="center" bgcolor="white" width="50" class="test">$qty6</td>
</tr>
<tr>
<td bgcolor="white" width="132" class="test">$city</td>
<td bgcolor="white" width="156" class="test">$state</td>
<td bgcolor="white" width="85" class="test">$zip</td>
<td bgcolor="white" width="13"><font size="2">7.</font></td>
<td nowrap bgcolor="white" class="test">$sup7</td>
<td align="center" bgcolor="white" width="50" class="test">$qty7</td>
</tr>
<tr>
<td valign="bottom" bgcolor="white" width="132"><b><font size="2" color="#003366">Phone</font></b></td>
<td colspan="5" valign="bottom" bgcolor="white"><b><font size="2" color="#003366">Contact Name</font></b></td>
</tr>
<tr>
<td bgcolor="white" width="132" class="test">$phone</td>
<td colspan="5" bgcolor="white" class="test">$contact</td>
</tr>
<tr>
<td colspan="6" valign="bottom" bgcolor="white"><b><font size="2" color="#003366">Notes</font></b></td>
</tr>
<tr>
<td colspan="6" bgcolor="white" class="test">$notes</td>
</tr>
<tr>
<td colspan="6" valign="bottom" bgcolor="white"><b><font size="2" color="#003366">Shipping Notes</font></b></td>
</tr>
<tr>
<td colspan="6" bgcolor="white" class="test">$shippingnotes</td>
</tr>
<tr>
<td colspan="6" bgcolor="white"><b><font size="2" color="#003366">Customer Relations Notes</font></b></td>
</tr>
<tr>
<td colspan="6" bgcolor="white" class="test">$cus_notes</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
Thanks for all of your help by the way. I really do appreciate all of you.
Wes/