...

View Full Version : Script Problem



stevan
06-05-2005, 03:32 PM
Please look at this script I am having a problem it will not send where it says destination all other works

THXS Steve

<?php
if (isset($_POST['submit'])) {
$to = 'steve@xxxxxxxxxxxxxxxxx';
$subject = $_POST['subject'];
$passenger = $_POST['passenger'];
$passenger2 = $_POST['passenger2'];
$message = $_POST['destination'];
if (mail($to, $subject, $passenger, $passenger2, $destination)) {
$message = "Mail sent!";
} else {
$message = "Couldn't send mail!";
}
}

echo (isset($message)) ? $message : '';
?>

<form name='email' method='post' action=''>
<p>Subject:
<input type='text' name='subject' />
<br />
Passenger:
<input type='text' name='passenger'>
Passenger:
<input type='text' name='passenger2'>
<br>
Destination:
<input type='text' name='destination'>
<br />
<input type='submit' name='submit' value='Send It' />
</p>
</form>

delinear
06-05-2005, 03:41 PM
$passenger = $_POST['passenger'];
$passenger2 = $_POST['passenger2'];
$message = $_POST['destination'];
if (mail($to, $subject, $passenger, $passenger2, $destination)) {

You declare $message = $_POST['destination'] but then you try to use the variable $destination instead, so I assume you meant to put $destination = $_POST['destination'].

Also if detsination is actually meant to appear in the body of the email along with passenger and passenger2 then you are using the mail() function wrongly. You need to concatenate the variables that make up the message into one variable (well, technically you don't but it's easier if you do), eg:


$msg = "Passenger 1 = $passenger\n";
$msg .= "PAssenger 2 = $passenger2\n";
$msg .= "Destination = $destination";
if (mail($to, $subject, $msg)) {

stevan
06-05-2005, 03:57 PM
Thxs for the help I am really new to this and I have 3 more questions

It sends to me BUT I want it have it send to another email adress that I could change when I fill out the form online

Also is there a way to make it so Passenger 1 and 2 are sxs instead of under each other

Lastly is there a way to make it look like this

Passenger 1 Stevan Brooks

Instead of

Passenger 1 = Stevan Brooks

No =

THXS VERY MUCH

STEVE :thumbsup:

delinear
06-05-2005, 04:12 PM
It sends to me BUT I want it have it send to another email adress that I could change when I fill out the form online

No problem, you can add that into the additional headers parameter of the mail function, so add a line that says:

$headers = "Cc: " . $_POST['additional_email'] . "\r\n";
where "additional email" is the name of the field in your form and then change the mail() line to read:

if (mail($to, $subject, $msg, $headers)) {
The mail should then also be CC'ed to the new email address you entered.



Also is there a way to make it so Passenger 1 and 2 are sxs instead of under each other

Sure, just take out the \n from the end of the passenger1 line so it appears like so:


$msg = "Passenger 1 = $passenger ";

(The \n just creates a newline in the email, so if you remove it then passenger 1 and 2 will appear side by side on one line instead of on separate lines).


Lastly is there a way to make it look like this

Passenger 1 Stevan Brooks

STEVE :thumbsup:

Again, that's simply a matter of removing the = so you would have:


$msg = "Passenger 1 $passenger ";

The whole thing together should look something like:


if (isset($_POST['submit'])) {
$to = 'steve@xxxxxxxxxxxxxxxxx';
$subject = $_POST['subject'];

$msg = "Passenger 1 " . $_POST['passenger'] . " ";
$msg .= "Passenger 2 " . $_POST['passenger2'] . "\n";
$msg .= $_POST['destination'];

$headers = "Cc: " . $_POST['additional_email'] . "\r\n";

if (mail($to, $subject, $msg, $headers)) {
$message = "Mail sent!";
} else {
$message = "Couldn't send mail!";
}
}

stevan
06-05-2005, 04:22 PM
Ok that worked great

BUT what I mean for the additional email adress was CAN I put a email field in the body of the form and use that to enter the eamil adress to send it to instead in the background where I have to go in and change it every time I send a invoice

Soory I am not the best at explaining it

STEVE

stevan
06-05-2005, 08:22 PM
Well all is working now

WheN I do this code

$msg = "Passenger 1 = $passenger";
$msg .= "Passenger 2 = $passenger2\n";

Is the a way to space them so they are not next to each other when sent

Passenger 1 = Steve Passenger 2 = Linda



THXS again

STEVE



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum