halojoy-
Ok, I'm just about there π I have different scripts that seem to do everything I need but I'm not sure how to combine them to work correctly.
Here is the code to email me the with the client's email address in the "From:" field when I receive the message:
<?php
$sender = $email;
$target = "me@myemail.com";
$subject = "New subscriber added to the newsletter";
$message = "Enter your message here including desired $variables and formatting from the subscription form such as
subscriber: $subscriber\ne-mail: $email\n and the like.";
$headers = "From: $sender\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
// send the message and give the confirmation back to the submitter
mail ($target, $subject, $message, $headers);
?>
Here is the code to send me all of the form's input items (text boxes, dropdowns, check boxes, etc.):
<?php
// ************Begin Configure***************
//Put where you want the email to go
$mailto = "me@myemail.com";
//Put where to redirect to after sending the email
$redirect = "thankyou-newsletter.html";
// ************End Configure****************
$headers = "From: $sender\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail ($target, $subject, $message, $headers);
foreach($HTTP_POST_VARS as $key => $value) {
$message .= $key . ': ' . $value;
$message .= "\n"; //Note the double quotes
}
if (@mail($mailto, $subject, $message)) {
header("Location: $redirect");
} else {
// This echo's the error message if the email did not send.
// You could change the text in between the <p> tags.
echo('<p>Mail could not be sent. Please use your back button to try again.</p>');
}
?>
Finally, here is the core of the code which checks for duplicate email addresses and if not found, adds the email to a text file:
<?php
// see if newsletter was checked
$email = trim(@$_POST['email'] );
//@suppresses the warning when email is not set
if ( isset($_POST['newsletter']) && !empty($email) ) {
$filename = 'subscribers.txt';
$name_arr = explode( ' ', $_POST['FullName'] );
$first_name = $name_arr[0];
$file_arr = file($filename);
$found = false;
foreach ($file_arr as $value) {
if (strpos($value, $_POST['email'])!==FALSE ) {
//this change was necessary: check manual for strpos
$found = true;
break;
}
}
if (!$found) {
$fp = fopen($filename, 'a+');//a+ means "create when it's not present"
fwrite($fp, $_POST['email'] . ',' . $_POST['FullName'] . "\n");
fclose($fp);
}
}
// this redirect is whether newsletter was checked or not
$URL = "thankyou-newsletter.html";
header ("Location: $URL");
?>
Any thoughts how I can mix all these to have all elements work. Thanks!