Forum Moderators: coopster

Message Too Old, No Replies

Add a break between message and signature contact form?

         

tech0925

3:45 am on Feb 27, 2011 (gmt 0)

10+ Year Member



Can anyone tell me how to add a break inbetween the sent message and my signature? Here is what my code looks like right now.


$email = $_REQUEST['email'] ;
$topic = $_REQUEST['topic'] ;
$message = $_REQUEST['message'] ;
$message1 = $message.$signature ;
$subject ="***$form Alert*** $topic" ;
$headers ="From: $email";


mail ($to, $subject, $message1, $headers) ;


When I recieve the email, it looks like this.

This is the message.Here is my signature.

How can I fix that. I am also using several variables in my header.php file including the $signature variable.

Thanks for any help on this!

Also, does anyone know how to make this send a copy to the sender?

penders

10:19 am on Feb 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In a plain text email you just need to insert a line feed ("\n") or two to create a break...

$message1 = $message."\n\n".$signature ;


To send a copy to the sender... you send another email to the sender! Nothing magic. You probably also want to change the from email address to something like "noreply@yourwebsite.com", adjust the subject etc.

tech0925

4:00 pm on Feb 27, 2011 (gmt 0)

10+ Year Member



Thank You penders! That helped alot. I am new to PHP and doing everything I can to learn it. I really want to be a successful PHP designer on down the road. Thanks again.

Matthew1980

6:09 pm on Feb 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,


$email = $_REQUEST['email'] ;
$topic = $_REQUEST['topic'] ;
$message = $_REQUEST['message'] ;


Gah! Security risk there, if you are getting these values from a form submission, use the $_POST global, and sanitise the data, especially if your using the user generated data directly INTO a mail() function, this could result in abuse of mail headers being done.

Turn into this:-

$email = $_POST['email']; <-- try an sanities this so that only valid email addresses are sent :)
$topic = $_POST['topic'];
$message = $_POST['message'];

$_REQUEST global can be useful, but not in the public domain, always stick to the way that the data is gathered; $_POST for form submissions - though you can do $_GET, but that's another lesson another day; and $_GET for 'getting' data from URL values, very useful.

As a rule, any user submitted data needs to be sanitised before it is used within an function that can end up in a data base or email, NEVER trust the user, always think about security, diligent coding does pay off.

There are plenty of little tutorials out there for this, and if you get stuck you can always post/ask questions here, and there are lots of people who can advise or suggest ways of improving your code.

Cheers,
MRb

tech0925

6:38 pm on Feb 27, 2011 (gmt 0)

10+ Year Member



Oh ok, thanks Matthew, so you are saying not to use $_REQUEST because it doesn't sanitize it correct, use $_POST instead b/c it does right? I do have a sanitize condition above this that looks like this:

function spamcheck($field)


//filter_var() sanitizes the e-mail

{
$field=filter_var($field, FILTER_SANITIZE_EMAIL);

//filter_var() validates the e-mail

if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}


if (isset($_REQUEST['email']))

//if "email" is filled out, proceed with sending

//check if the email address is invalid
$mailcheck = spamcheck($_REQUEST['email']);
if ($mailcheck==FALSE)
{
echo "The form was not properly filled out, please press the back button and try again.";
}
else


//send email if validation has passed

Is this doing the same thing?


Thanks

Matthew1980

7:53 pm on Feb 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there tech0925,

>>so you are saying not to use $_REQUEST because it doesn't sanitize it correct, use $_POST instead b/c it does right?

Not quite, $_REQUEST and $_POST are just different super globals that are available in php that you can get data from IF they are set (Have state..)

$_REQUEST [php.net] is a something that carries a lot of data that you may not be aware that your asking for. The data contained within this array is by default a string (chars) and so will need filtering for any potentially malicious code injection attempts.

The example code that you supplied works fine, and I tend to advocate the filter_var() with those constant flags set, and it saves you having to work out the regex patterns for use in the preg_match() option.. So yes the code you have there does the job nicely.

All I was suggesting that instead of using $_REQUEST to retrieve this set data, just do it directly with $_POST, as this is accessing that particular global directly, therefore only requesting one set of the array.

The only other thing as I will suggest is for the 'topic' & 'message' fields, pass them through the strip_tags() function, then you will make the data contain NO html type tags, which makes it a little safer, and lastly run it through the trim() function so that you get rid of any extraneous white space trying to be submitted.

I hope that makes more sense to you, and my apologies for confusing you.

Cheers,
MRb

tech0925

10:29 pm on Feb 27, 2011 (gmt 0)

10+ Year Member



Thanks! I am quite new to PHP and trying hard to understand it. I want to learn to write advanced applications with it but for now I am trying to wrap my mind around something simpler like this form. LOL

Unfortunately, a lot of stuff that you mentioned (trim and strip tags functions) I have no idea what they are and how to use them. =( I am going to send you a PM ok.

Thanks again!