FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Re: Php variables to an email.
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Php variables to an email. [message #169348] Tue, 07 September 2010 23:52 Go to next message
GarryJones is currently offline  GarryJones
Messages: 21
Registered: September 2010
Karma: 0
Junior Member
> Some code for us to had a clue what it is about would be good. none of
> us is clairvoyant here. ;)

Ok, I thought maybe it would be quicker if someone could just point me
in the right direction, it must be an everyday thing to do with php
but I can't find a simple solution. Just websites tha confuse me with
great complex answers involving pear,perl and mime but I am not
interested in learning something new, I just need this to work in an
easy way with php.

After reading in the values I am trying to send the values $bokfor and
$bokeft in the following email. I receive the php code and not the
actual variable.

<?php
// multiple recipients
$to = 'garry(at)vasatrampet(dot)se' . ', ';
$to .= 'info(at)vasatrampet(dot)se';

// subject
$subject = 'Whatever';

// message
$message = "
<html>
<head>
<title>Bokningsbekräftelse</title>
</head>
<body>
<p>Hej<?= $bokfor ?>&nbsp;<?= $bokeft ?>, tack för din bokning!</p>
</body>
</html>
";

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Garry <garry(at)cykeltours(dot)se>' . "\r\n";
$headers .= 'From: Garry <garry(at)vasatrampet(dot)se>' . "\r\n";
$headers .= 'Bcc: garry(at)vasatrampet(dot)se' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>
Re: Php variables to an email. [message #169349 is a reply to message #169348] Tue, 07 September 2010 23:57 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
GarryJones wrote:
>> Some code for us to had a clue what it is about would be good. none of
>> us is clairvoyant here. ;)
>
> Ok, I thought maybe it would be quicker if someone could just point me
> in the right direction, it must be an everyday thing to do with php
> but I can't find a simple solution. Just websites tha confuse me with
> great complex answers involving pear,perl and mime but I am not
> interested in learning something new, I just need this to work in an
> easy way with php.
>
> After reading in the values I am trying to send the values $bokfor and
> $bokeft in the following email. I receive the php code and not the
> actual variable.
>
> <?php
> // multiple recipients
> $to = 'garry(at)vasatrampet(dot)se' . ', ';
> $to .= 'info(at)vasatrampet(dot)se';
>
> // subject
> $subject = 'Whatever';
>
> // message
> $message = "
> <html>
> <head>
> <title>Bokningsbekräftelse</title>
> </head>
> <body>
> <p>Hej".= $bokfor." ".$bokeft ." tack för din bokning!</p>
> </body>
> </html>
> ";
>
> // To send HTML mail, the Content-type header must be set
> $headers = 'MIME-Version: 1.0' . "\r\n";
> $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
>
> // Additional headers
> $headers .= 'To: Garry <garry(at)cykeltours(dot)se>' . "\r\n";
> $headers .= 'From: Garry <garry(at)vasatrampet(dot)se>' . "\r\n";
> $headers .= 'Bcc: garry(at)vasatrampet(dot)se' . "\r\n";
>
> // Mail it
> mail($to, $subject, $message, $headers);
> ?>
>

See the line edited above:-

<p>Hej ".$bokfor." ".$bokeft." tack för din bokning!</p>
Re: Php variables to an email. [message #169350 is a reply to message #169349] Wed, 08 September 2010 00:15 Go to previous messageGo to next message
Marious Barrier is currently offline  Marious Barrier
Messages: 25
Registered: September 2010
Karma: 0
Junior Member
On 09/07/2010 07:57 PM, The Natural Philosopher wrote:
> GarryJones wrote:
>>> Some code for us to had a clue what it is about would be good. none of
>>> us is clairvoyant here. ;)
>>
>> Ok, I thought maybe it would be quicker if someone could just point me
>> in the right direction, it must be an everyday thing to do with php
>> but I can't find a simple solution. Just websites tha confuse me with
>> great complex answers involving pear,perl and mime but I am not
>> interested in learning something new, I just need this to work in an
>> easy way with php.
>>
>> After reading in the values I am trying to send the values $bokfor and
>> $bokeft in the following email. I receive the php code and not the
>> actual variable.
>>
>> <?php
>> // multiple recipients
>> $to = 'garry(at)vasatrampet(dot)se' . ', ';
>> $to .= 'info(at)vasatrampet(dot)se';
>>
>> // subject
>> $subject = 'Whatever';
>>
>> // message
>> $message = "
>> <html>
>> <head>
>> <title>Bokningsbekräftelse</title>
>> </head>
>> <body>
>> <p>Hej".= $bokfor." ".$bokeft ." tack för din bokning!</p>
>> </body>
>> </html>
>> ";
>>
>> // To send HTML mail, the Content-type header must be set
>> $headers = 'MIME-Version: 1.0' . "\r\n";
>> $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
>>
>> // Additional headers
>> $headers .= 'To: Garry <garry(at)cykeltours(dot)se>' . "\r\n";
>> $headers .= 'From: Garry <garry(at)vasatrampet(dot)se>' . "\r\n";
>> $headers .= 'Bcc: garry(at)vasatrampet(dot)se' . "\r\n";
>>
>> // Mail it
>> mail($to, $subject, $message, $headers);
>> ?>
>>
>
> See the line edited above:-
>
> <p>Hej ".$bokfor." ".$bokeft." tack för din bokning!</p>

There is still an = symbol there.
Re: Php variables to an email. [message #169351 is a reply to message #169348] Wed, 08 September 2010 00:35 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 9/7/2010 7:52 PM, GarryJones wrote:
>> Some code for us to had a clue what it is about would be good. none of
>> us is clairvoyant here. ;)
>
> Ok, I thought maybe it would be quicker if someone could just point me
> in the right direction, it must be an everyday thing to do with php
> but I can't find a simple solution. Just websites tha confuse me with
> great complex answers involving pear,perl and mime but I am not
> interested in learning something new, I just need this to work in an
> easy way with php.
>
> After reading in the values I am trying to send the values $bokfor and
> $bokeft in the following email. I receive the php code and not the
> actual variable.
>
> <?php
> // multiple recipients
> $to = 'garry(at)vasatrampet(dot)se' . ', ';
> $to .= 'info(at)vasatrampet(dot)se';
>
> // subject
> $subject = 'Whatever';
>
> // message
> $message = "
> <html>
> <head>
> <title>Bokningsbekräftelse</title>
> </head>
> <body>
> <p>Hej<?= $bokfor ?>&nbsp;<?= $bokeft ?>, tack för din bokning!</p>
> </body>
> </html>
> ";
>
> // To send HTML mail, the Content-type header must be set
> $headers = 'MIME-Version: 1.0' . "\r\n";
> $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
>
> // Additional headers
> $headers .= 'To: Garry<garry(at)cykeltours(dot)se>' . "\r\n";
> $headers .= 'From: Garry<garry(at)vasatrampet(dot)se>' . "\r\n";
> $headers .= 'Bcc: garry(at)vasatrampet(dot)se' . "\r\n";
>
> // Mail it
> mail($to, $subject, $message, $headers);
> ?>
>

Garry, this line is your problem:

<p>Hej<?= $bokfor ?>&nbsp;<?= $bokeft ?>, tack för din bokning!</p>

You're already in PHP - the <?= does nothing for you, other than print
out those characters. However, the ?> at the end terminates PHP; then
your &nbsp; and the rest is output to the browser.

However, I'm very surprised you didn't get an error - this would be
invalid PHP code (no ending ';' statement delimiter). You should ensure
your development system has the following in your php.ini file:

error_reporting=E_ALL // E_ALL | E_STRICT is even better
display_errors=on

Additionally, using <?= outputs to the screen, not appends to the
string, as you wish. However, it also depends on short_open_tags=on in
your php.ini file - not a good thing to count on (among other things, it
interferes with XML delimiters).

These two statements are exactly equivalent:

<?= $bokfor ?>

and

<?php echo $bokfor; ?>

If you would have used the longer version, it might have caught your
attention, also.

The solution is to change the line to:

<p>Hej" . $bokfor . "&nbsp;" . $bokeft . ', tack för din bokning!</p>

Or, since you're using double quotes, which will interpret PHP variables
within the string, you could just use:

<p>Hej $bokfor &nbsp; $bokeft, tack för din bokning!</p>

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Php variables to an email. [message #169356 is a reply to message #169350] Wed, 08 September 2010 11:53 Go to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Marious Barrier wrote:
> On 09/07/2010 07:57 PM, The Natural Philosopher wrote:
>> GarryJones wrote:
>>>> Some code for us to had a clue what it is about would be good. none of
>>>> us is clairvoyant here. ;)
>>>
>>> Ok, I thought maybe it would be quicker if someone could just point me
>>> in the right direction, it must be an everyday thing to do with php
>>> but I can't find a simple solution. Just websites tha confuse me with
>>> great complex answers involving pear,perl and mime but I am not
>>> interested in learning something new, I just need this to work in an
>>> easy way with php.
>>>
>>> After reading in the values I am trying to send the values $bokfor and
>>> $bokeft in the following email. I receive the php code and not the
>>> actual variable.
>>>
>>> <?php
>>> // multiple recipients
>>> $to = 'garry(at)vasatrampet(dot)se' . ', ';
>>> $to .= 'info(at)vasatrampet(dot)se';
>>>
>>> // subject
>>> $subject = 'Whatever';
>>>
>>> // message
>>> $message = "
>>> <html>
>>> <head>
>>> <title>Bokningsbekräftelse</title>
>>> </head>
>>> <body>
>>> <p>Hej".= $bokfor." ".$bokeft ." tack för din bokning!</p>
>>> </body>
>>> </html>
>>> ";
>>>
>>> // To send HTML mail, the Content-type header must be set
>>> $headers = 'MIME-Version: 1.0' . "\r\n";
>>> $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
>>>
>>> // Additional headers
>>> $headers .= 'To: Garry <garry(at)cykeltours(dot)se>' . "\r\n";
>>> $headers .= 'From: Garry <garry(at)vasatrampet(dot)se>' . "\r\n";
>>> $headers .= 'Bcc: garry(at)vasatrampet(dot)se' . "\r\n";
>>>
>>> // Mail it
>>> mail($to, $subject, $message, $headers);
>>> ?>
>>>
>>
>> See the line edited above:-
>>
>> <p>Hej ".$bokfor." ".$bokeft." tack för din bokning!</p>
>
> There is still an = symbol there.
I know. See the last line I posted.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Openssl through HTTP Proxy (cUrl?)
Next Topic: executing command with shell_exec()
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 12:32:14 GMT 2024

Total time taken to generate the page: 0.04547 seconds