mattyvx Posted November 28, 2009 Share Posted November 28, 2009 All, In learning PHP I took a mailing script from a website, after learning PHP over the past few months i've removed alot of the sections of the script and im left with the below; <?php // ------------- MAIL SCRIPT ------------------------ $copyto = "sends copy to me" ; $mailto = "sends a copy to my autoresponder" ; $subject = "Message subject" ; $thankyouurl = "http://www.mysite.com/thankyou.php" ; $uself = 0; // can I just remove this?! $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; //What is the difference between the two? What is the purpose? $content_type = 'Content-Type: text/plain; charset="iso-8859-1"' ; $messageproper = "This message was sent from:\n" . "$http_referrer\n" . "If you did not fill out this form please contact myemail \n" . "------------------------------------------------------------\n\n" . //here i echo form variables "\n------------------------------------------------------------\n" ; $headers = "From: \"$Usersname\" <$mailto>" . $headersep . "Reply-To: \"$Usersname\" <$email>" . $headersep . 'MIME-Version: 1.0' . $headersep . $content_type ; mail($mailto, $subject, $messageproper, $headers ); mail($copyto, $subject, $messageproper, $headers ); echo '<meta http-equiv="refresh" content="0.5;url=thankyou.php" />'; } ?> The script send me a message as hard copy, then sends a message to an automated email address which in turn sends a welcome email to the users $email address collected in the form. The script works fine but I have some questions. 1) Is the script "secure" - the $email variable is sanitised previously 2) Should I add anything to the script to improve functionality 3) See comments in script about the $headersep. Thanks Link to comment https://forums.phpfreaks.com/topic/183242-form-to-email-finished-script/ Share on other sites More sharing options...
MisterWebz Posted November 28, 2009 Share Posted November 28, 2009 if $uself is not set or equals 0, then perform: "\r\n. If it's false, then it'll output : "\n". and it's already set to 0, so what it basically does is output "\n" all the time. <?php $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; //What is the difference between the two? What is the purpose? ?> if the $uself is only used for this, then you can just use the code below and delete the $uself: <?php $headersep = "\r\n"; ?> Link to comment https://forums.phpfreaks.com/topic/183242-form-to-email-finished-script/#findComment-967115 Share on other sites More sharing options...
mattyvx Posted November 28, 2009 Author Share Posted November 28, 2009 ok thanks i got that but why would I need to use either the \r\n or just \n? I can see it serperates the values in $header but it is required and which applications would require \r\n as opposed to \n... Link to comment https://forums.phpfreaks.com/topic/183242-form-to-email-finished-script/#findComment-967150 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.