Jump to content

Form to Email - Finished script?


mattyvx

Recommended Posts

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

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";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.