Herg Posted October 23, 2009 Share Posted October 23, 2009 (edited) Hello guys,I have a small problem with a php mailer. I am sure you could help me and thank you in advance:Situtation:I am about to establish a newsletter. I manage the newsletter with sendblaster (www.sendblaster.com). To unsubscribe from the newsletter, people would have to send an e-mail with the subject "unsubscribe". The program reads that e-mail and removes them from the list of recipients.I want the users also to be able to unsibscribe via a webform. Therefore I modified the free registration php mailer to fullfill the needs of unsubscribing. All works fine, exept one thing:When I receive the e-mail, the displayed "sender" is always the webserver. But I want the sender to be the e-mail adress people have netered into the form. In the code listed below, that should be the varible $email <?php$emailmanager = 'NOTTODEDISCLOSED'; $urlok = 'unsubscribe-confirm-ok.htm';$urlko = 'unsubscribe-confirm-ko.htm';error_reporting(0);set_magic_quotes_runtime (0);if (get_magic_quotes_gpc()) { foreach($_POST as $k=>$v) $_POST[$k] = stripslashes($v); foreach($_COOKIE as $k=>$v) $_COOKIE[$k] = stripslashes($v);}$msg = $_COOKIE['sb'.$_GET['id']];$email = trim($_GET['email']);$Ok = ereg("^([a-zA-Z0-9_\.-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", $email);$headers = 'From: ' . $email . "\n";$headers .= 'MIME-Version: 1.0' ."\n";$headers .= 'Content-Type: text/plain; charset=iso-8859-1' ."\n";$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\n";if ($Ok && ($msg != '')) { mail($email,'Unsubscribe',$headers); Header("Location: $urlok");} else { Header("Location: $urlko");}?>In my opinion, the sender should be derived from the variable $email. But it does not work. However, when I enter $emailmanager instead, this variable will be shown as the sender. I really don't know why this is...Thank you so much for your help in advance!Herg Edited October 23, 2009 by Herg Link to comment Share on other sites More sharing options...
Herg Posted October 28, 2009 Author Share Posted October 28, 2009 (edited) Hey guys. I solved the problem. I was just too silly to read the php syntax properly.The function mail must be fed with variables (in this order): to, subject, message, headers.Since only need an empty mail with correct headers, I had removed the 'message' string in the first place.So below you will find the correct code for the relevant part for sending a the mail as I wanted it to be....$headers .= 'From: '.$email."\n";$headers .= 'MIME-Version: 1.0' ."\n";$headers .= 'Content-Type: text/plain; charset=iso-8859-1' ."\n";$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\n";if ($Ok && ($msg != '')) { mail($emailmanager, 'Unsubscribe', 'Abmeldung', $headers); Header("Location: $urlok");} else { Header("Location: $urlko");}?> Edited October 28, 2009 by Herg Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now