Passing variable to mail page that sends mail via HTML

I’m new to PHP but been programing in CFML for 7 years and I’m having a bit of trouble figuring out how to convert one of my mail pages. I have a form (mail.htm) posting to (mail_act.php) page that has this PHP code in it. I am getting the email in HTML fine I just cant get the variable to come through the email comes through with the $_Post’s where there supposed to be, just no variables…lol. Please help me get over this hump…Thanks much!!

[code]

<?php $to = "[email protected]"; $subject = "Trip Request"; $message = '

Hooked Up Sportfishing Request

Name:$_POST["fname"]

Email: $_POST["email"]

Phone:$_POST["phone"]

Address:

$_POST["street"]
$_POST["city"] $_POST["state"] $_POST["zipcode"]

Request:

$_POST["hu_req"]

'; $headers = 'MIME-Version: 1.0' . "rn"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn"; $headers .= 'From: Hookedup_Trip_Request ' . "rn"; mail($to, $subject, $message, $headers); ?>[/code]

Try this…

If it doesnt work let me know i typed it up fast

[php]

<?php $city = $_POST["city"]; $state = $_POST["state"]; $email = $_POST["email"]; $first = $_POST["fname"]; $phone = $_POST["phone"]; $street = $_POST["street"]; $zip = $_POST["zipcode"]; $req = $_POST["hu_req"]; $to = "[email protected]"; $subject = "Trip Request"; $message = '

Hooked Up Sportfishing Request

Name:$first

Email: $email

Phone:$phone

Address:

$street
$city $state $zip

Request:

$req

'; $headers = 'MIME-Version: 1.0' . "rn"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn"; $headers .= 'From: Hookedup_Trip_Request ' . "rn"; mail($to, $subject, $message, $headers); ?>

[/php]

THShadow

Thanks for the reply I tried the code and the same thing happened, no variables. So this result tells me that PHP is working since it sent the email, but I must be coding wrong since variables are not being passed to the email ($message) string.

Email that was returned came through like this.


Hooked Up Sportfishing Request 

Name:$first

Email: $email

Phone:$phone

Address:

$street
$city $state $zip

Request:

$req

It’s because you put variables between single quotes, but expect them to be parsed. Behold:

[php]
$myVar = “World”;

// Variable between single quotes - will output: Hello $myVar
echo ‘Hello $myVar’;

// Variable between double quotes - will output: Hello World
echo “Hello $myVar”;

// Variable outside quotes - both will output: Hello World
echo 'Hello '.$myVar;
echo "Hello ".$myVar;
[/php]

Personally I think putting the variables outside the quotes is the most graceful option :slight_smile:

Ok I tried this and it didnot work, received php error. I tried using double quotes (") and this didn’t seem to work due to the double quotes in the HTML peice of the string. So I broke the string up with single quotes but no go.

[code]<?php

$city = $_POST[“city”];
$state = $_POST[“state”];
$email = $_POST[“email”];
$first = $_POST[“fname”];
$phone = $_POST[“phone”];
$street = $_POST[“street”];
$zip = $_POST[“zipcode”];
$req = $_POST[“hu_req”];

$to = "[email protected]";
$subject = “Trip Request”;
$message = ’

Hooked Up Sportfishing Request

Name:'.$first'

Email: <a href="mailto:'.$email'>'.$email'</a></p> <p><strong>Phone:</strong>'.$phone'</p> <p><strong>Address:</strong></p> <p>'.$street'<br> '.$city' '.$state' '.$zip'</p> <p><strong>Request:</strong></p> <p>'.$req'</p>'; $headers = 'MIME-Version: 1.0' . "rn"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn"; $headers .= 'From: Hookedup_Trip_Request ' . "rn"; mail($to, $subject, $message, $headers); ?> [/code]

Well, that’s because you’re forgetting the period behind each of the variables (period is concatenating strings in PHP). Put one between the variable and the rest of the string and tell us if it works.

Alternatively, try putting the following code at the top of your PHP code:

[php]error_reporting(E_ALL);[/php]

And tell us if you get any errors (and if so, which ones).

Zyppora

Thank you for sharing your knowledge with me on this, I’m grateful for your help.

Now that the PHP has the correct (’) and (.)'s in the correct places everything is working great!! Thank you for your help!!

I hope I can become more efficient in this language as its performance is much better then CFML. I spend time reading php.net yet is there another refrence that you would recommend for a newbie PHP coder?

Thank you for your time!

ANSWER:

[code]

<?php $city = $_POST["city"]; $state = $_POST["state"]; $email = $_POST["email"]; $first = $_POST["fname"]; $phone = $_POST["phone"]; $street = $_POST["street"]; $zip = $_POST["zipcode"]; $req = $_POST["hu_req"]; $to = " [email protected] , [email protected] "; $subject = "Hooked up sportfishing request"; $message = '

Hooked Up Sportfishing Request

Name:' . $first . '

Email: ' . $email . '

Phone:' . $phone . '

Address:

' . $street . '
' . $city . ' ' . $state . ' ' . $zip . '

Request:

' . $req . '

'; $headers = 'MIME-Version: 1.0' . "rn"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn"; $headers .= 'From:' . $email . "n"; mail($to, $subject, $message, $headers); ?>[/code]

I’m having one other issue. When this email is sent I have it going to two email address. One goes to a yahoo.com address and one goes to a mail2web address ([email protected]). The yahoo address receives them fine and the mail2web address is not receiving them at all. Does anyone know what might be going on here? I’ve verified the obvious email address and tested both email accounts.

In Response to my last post this was caused by somthing my hosting company was doing. No problems anymore.

I thank everyone for their help and time!!

I'm having one other issue. When this email is sent I have it going to two email address. One goes to a yahoo.com address and one goes to a mail2web address ([email protected]). The yahoo address receives them fine and the mail2web address is not receiving them at all. Does anyone know what might be going on here? I've verified the obvious email address and tested both email accounts.

You could try searching google for PHP tutorials, those usually work. Or install a premade script and start tinkering with that (that’s the way I learned).

Sponsor our Newsletter | Privacy Policy | Terms of Service