Problem: Passing Variable to Email $message

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

alsaffar
New php-forum User
New php-forum User
Posts: 4
Joined: Wed Aug 14, 2002 11:49 am

Problem: Passing Variable to Email $message

Postby alsaffar » Thu Aug 22, 2002 5:18 pm

Hi there,

I have an HTML Form (not complete):

<FORM ACTION="JoinList.php" METHOD="POST">
<INPUT TYPE="TEXT" NAME"joinEmail">
<INPUT TYPE="SUBMIT">
</FORM>

and a PHP script (not complete):

$to = $HTTP_POST_VARS[joinEmail];
$subject = "Thanx 4 Joining our List";
$message = '
<HTML><CENTER><B>
Thank you for Joining our Mail List with the email: <? echo "$to"; ?>
</HTML>';
$headers = "From: MyCompany<list@domain.com>\r\n";

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

---------------------------------------------------------------------

When the user hit the submit button in the HTML page, an email is sent to the user, until now everything is fine, but the problem is that the "$to" field is not shown in the email message, I tried to put $HTTP_POST_VARS[joinEmail] instead of $to but nothing works.

Is the problem that I can't use variables in emails?

So, any idea how can I use POST variables in the email's message?

PleasE FeeD ME BacK & HaVe a GooD DaY ;)

Ali

DoppyNL

Postby DoppyNL » Thu Aug 22, 2002 11:28 pm

remember that you're simply building a string that will be send as message from an e-mail.

you can do one of the following (both work)
$variable = ' BUURP';

Code: Select all

$message = 'normal string ' . $variable . ' blablabla';

Code: Select all

$message = "normal string $variable blablabla";


both result in message being:
normal string BUURP blablabla


manual page: http://www.php.net/manual/en/language.types.string.php

Greetz Daan

Jay

Re: Problem: Passing Variable to Email $message

Postby Jay » Fri Aug 23, 2002 2:07 am

Your problem is here:

Code: Select all

$message = '
<HTML><CENTER><B>
Thank you for Joining our Mail List with the email: <? echo "$to"; ?>
</HTML>';

You're trying to parse PHP when you're already in PHP mode, AND you're attempting to access a variable value within single quotes!

Change it to

Code: Select all

$message = '
<HTML><CENTER><B>
Thank you for Joining our Mail List with the email: '.$to.'</HTML>';


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 4 guests