Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Script Problem

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    271
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Script Problem

    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>

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $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:

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

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    271
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by stevan
    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:
    PHP Code:
    $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:
    PHP Code:
    if (mail($to$subject$msg$headers)) { 
    The mail should then also be CC'ed to the new email address you entered.


    Quote Originally Posted by stevan
    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:

    PHP Code:
    $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
    Again, that's simply a matter of removing the = so you would have:

    PHP Code:
    $msg "Passenger 1 $passenger "
    The whole thing together should look something like:

    PHP Code:
    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!";
        }


  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    271
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    271
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •