Forum Moderators: coopster
<a href="emailthisperson.php?id=1234">Email this person</a>
<form action="emailthisperson_submission.php" method="post">
<input type="hidden" name="id" value="1234">
$recipients = array (
'WEBMASTER' => 'webmaster@example.com', // When something goes wrong
'1234' => 'someone@example.com',
'8362' => 'bob@example.co.uk',
'9072' => 'fred@anotherexample.com',
);
$recipientId = isset($_POST['id']) ? $_POST['id'] : 'WEBMASTER';
$recipientId = isset($recipients[$recipientId]) ? $recipientId : 'WEBMASTER';
$recipientEmail = $recipients[$recipientId];
I am a little unsure of how to do this...
<form method="post" action="url-to-form-script.php">
Name: <input name="name" type="text" /><br />
Email: <input name="email" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
<?php
$recipients = array (
'WEBMASTER' => "name@my-domain.com",
'001' => "name@some-domain.com",
'002' => "name@another-domain.com",
'003' => "name@yet-another-domain.com",
);
$email = $_POST['email'] ;
$message = $_POST['name'] ;
$message .= $_POST['message'] ;
$recipientId = isset($_POST['id']) ? $_POST['id'] : 'WEBMASTER';
$recipientId = isset($recipients[$recipientId]) ? $recipientId : 'WEBMASTER';
$recipientEmail = $recipients[$recipientId];
mail( "$recipientEmail", "Feedback Form Results",
$message, "From: $email" );
header( "Location: www.redirect-to-this.com" );
?>
<?php
// Retreive the value of the 'id' param in the URL (if it exists)
// Convert to HTML entities to prevent code injection
$ID_VALUE = isset($_GET['id']) ? htmlentities($_GET['id']) : '';
?>
<form method="post" action="url-to-form-script.php">
<input type="hidden" name="id" value="<?php echo $ID_VALUE; ?>" />
:
WEBMASTER,name@my-domain.com
001,name@some-domain.com
002,name@another-domain.com
003,name@yet-another-domain.com
$recipients = array (
'WEBMASTER' => "name@my-domain.com",
'001' => "name@some-domain.com",
'002' => "name@another-domain.com",
'003' => "name@yet-another-domain.com",
);
$filename = 'data/emailaddresses.csv';
$recipients = array();
if (($handle = fopen($filename, 'r')) !== false) {
while (($data = fgetcsv($handle, 200)) !== false) {
$recipients[$data[0]] = $data[1];
}
fclose($handle);
}