PHP help - turning a variable into non-html text

konerboy

Run piggy Run!
Reaction score
95
hey guys i have a problem here i borrowed a email system from a tutorial but whenever i get the mails the text variables isn't converted so i basicly get a message, with the subject: message from $strname, with a message that reads: $straddress, is there anyone here that can make the subject be the actual name and make the mail contain the right comment?

Html if needed

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<title>Untitled Document</title>
</head>

<body style="padding:3px; margin:0px;" bgcolor="#FFFFFF">
<table cellpadding="0" cellspacing="0" border="0" width="440">

<tr><td style="height:10px"></td></tr>
<tr>
<td colspan="2" style="text-align:justify; line-height:15px;" class="body">

<form name="frm" method="POST" action="careersuccess2.php" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>

<td width="183px" height="23px" class="body">name</td></tr>
<tr>
<td width="74%"><input type="text" name="strname" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="224px" height="21px" class="body">comment</td></tr>
<tr>
<td width="74%"><textarea cols="16" name="straddress"></textfield></td>
</tr>
<tr><td style="height:10px"></td></tr>
<tr>
<td colspan="3" align="center">
<input type="submit" value="Send" name="submit" onClick="return validate();"> <input type="reset" value="Reset" name="reset">
</td>
</tr>

</table>

</body>
</html>

Php

<?php

$strname=ucfirst($_REQUEST["strname"]);
$straddress=ucfirst($_REQUEST["straddress"]);
$strcity=ucfirst($_REQUEST["strcity"]);
$strstate=ucfirst($_REQUEST["strstate"]);

$stremail=$_REQUEST["stremail"];
$strcomments=ucfirst($_REQUEST["strcomments"]);







$message= '

$straddress.


';

// MAIL SUBJECT

$subject = " message from $strname ";

// TO MAIL ADDRESS


$to="[email protected]";

/*
// MAIL HEADERS

$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: Name <[email protected]>\n";

*/



// MAIL HEADERS with attachment

$num = md5(time());

//Normal headers

$headers = "From: Name<[email protected]>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";

// This two steps to help avoid spam

$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";

// With message

$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";





// SEND MAIL

@mail($to, $subject, $message, $headers);

?>


can this be fixed or do i need MySql or w/e to do this?
 
Where did you learn php from? :rolleyes:

Code:
$subject = ' message from $strname ';

Should be

Code:
$subject = " message from $strname ";
or
$subject = " message from ".$strname;

Same for the others. Stop putting variables directly inside "". It's more comfortable, but it can lead to such problems.

. is a concatenation operator for strings. Put actual text inside "" and variables outside it.

Example:

Code:
echo "Hello " . $guest_name . "!";
 
You have to validate the user input. Any user-provided data must not contain any linebreaks, otherwise your script will be used to spam whatever a malicious user gets paid for.

Otherwise, I'll submit a subject like " --- BUY VIAGRA NOW!!!\nTo: [long list of email addresses\n[my other mail content...]".

If you'd like to send email using PHP, use the PEAR packages Mail and Mail_Mime.

While we're at it, don't use $_REQUEST, but either $_GET or $_POST, whatever you're expecting in your form. It's much safer than a magic array that's a mix of cookie content and HTTP headers.
 
ok it worked now. now another thing.

how can i make the "stradress" and "strname" appear next to each other in the $message?

i've tried echo ad other things but they've just been giving trouble
 
Code:
$message= $stradress . $strname;

might work.
 
> it won't work
Why not?
 
It'll work, but it's silly imo for just a space.

Say a $var is = to "pie"

$str = 'I like ' . $var; I like pie
$str = "I like $var"; I like pie
$str = 'I like $var'; I like $var
 
Embedding a variable in a double-quoted string is faster than concatenation, in terms of execution speed.

If you are worried about readability, just use braces {} around the variable:

PHP:
$food = 'Ice cream';
$str = "I think {$food} tastes great!"; // I think Ice cream tastes great!
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top