Email based on nicknames???
Moderator: General Moderators
Email based on nicknames???
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?
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?
- Leviathan
- Forum Commoner
- Posts: 36
- Joined: Tue Sep 23, 2003 7:00 pm
- Location: Waterloo, ON (Currently in Vancouver, BC)
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.
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.
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();
}
?>-
Cruzado_Mainfrm
- Forum Contributor
- Posts: 346
- Joined: Sun Jun 15, 2003 11:22 pm
- Location: Miami, FL
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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.
...and this is the part that sends the templated email...
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.
Thanks for all of your help by the way. I really do appreciate all of you.
Wes/
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);
?>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);
?>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>Wes/