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: PHP Issue

  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    PHP Issue

    Hello guys , hope everybody is okay .
    I'm having a little problem with a php code

    PHP Code:
    <? //enter recipient's email address.  If multiple recipients, separate with comma:
    $to="someemail@yourdomain.com";
    if(isset(
    $_POST['email'])){
    if(
    ereg("^[^@]{1,64}@[^@]{1,200}\.[a-zA-Z]{2,3}$",$_POST['email'])){
    mail($to,$_POST['subject'],$_POST['message'],"From: ".$_POST['email']);
    echo
    '<font color="green">Your message was sent</font>';
    }else echo
    '<font color="red">"'.$_POST['email'].'" is not a valid email address.</font>';
    }
    ?><form action="" method="post"><table><tr><td>Your Email:</td><td><input name="email"></td></tr>
    <tr><td>Subject:</td><td><input name="subject"></td></tr></table>Message:
    <br><textarea rows="8" cols="50" name="message"></textarea><br>
    <input type="submit" value="send"></form>

    Okay, now to explain more on the issue , the code is working just fine as it now i'm trying to add more text areas & inputs like i want to add more information to be sent within the page like ex: Firstname , Lastname, Arrival Date , ect...
    i've added them and prepared tables and everything but my biggest issue get related to $_POST

    Check here .

    PHP Code:
    mail($to,$_POST['subject'],$_POST['message'],"From: ".$_POST['email']); 
    Now in $_POST['message'] , it's working but when trying to add more inputs like ['L_name'] , or anything else the script stop working and messages never sent .

    Any ideas how should i modify the code to fix it .

    Best Regards

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    You can't just toss parameters at the mail function, if that's what you're trying to do - that's not how it works. Consult the documentation here:
    http://php.net/manual/en/function.mail.php
    Are you a Help Vampire?

  • Users who have thanked tomws for this post:

    Hostlb (01-19-2010)

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tomws View Post
    You can't just toss parameters at the mail function, if that's what you're trying to do - that's not how it works. Consult the documentation here:
    http://php.net/manual/en/function.mail.php
    Dear , what i want to do is simply add more values to be sent in the mail

    the code as it's in here send what is typed in the textarea , called ['message'] what if i want to add second textarea and 3rd one for expamle message2 & message3 how should i edit that prefix

    $_POST['message']
    should i put it like this

    $_POST['message'],$_POST['message2'],$_POST['message3']

    or it should be typed in another way , because i tired this but it haven't worked .

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Another way, as already suggested. The documentation, linked above, shows that the second argument to the mail function is the message body. Whatever you want to send, cram it all into one variable and use that as the second argument.
    Are you a Help Vampire?

  • Users who have thanked tomws for this post:

    Hostlb (01-19-2010)

  • #5
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I have read the documentation from the top to the end and i have edited my code but after applying the second value the script cease sending
    check what i have edited

    PHP Code:
    <? php>
    $to="ht.server@gmail.com";
    $message=$_POST['message'];
    $lname=$_POST['lname'];
    if(isset(
    $_POST['email'])){
    if(
    ereg("^[^@]{1,64}@[^@]{1,200}\.[a-zA-Z]{2,3}$",$_POST['email'])){
    mail($to,$_POST['subject'], $lname$message"From: ".$_POST['email']);
    echo
    '<font color="Blue">Your message was sent</font>';
    }else echo
    '<font color="red">"'.$_POST['email'].'" is not a valid email address.</font>';
    }
    ?>
    i have added 3rd and 4th line
    and edited the $POST .

    I should mention , that it works when using only one value like message or lname , after adding second value it stop sending .

    any ideas ?

    Regards

  • #6
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by Hostlb View Post
    I have read the documentation from the top to the end and i have edited my code but after applying the second value the script cease sending
    No, that's still doing it the first way you tried and it's still not going to work - you can't throw in extra parameters out of nowhere. I mis-posted in the last response:

    Quote Originally Posted by tomws View Post
    Whatever you want to send, cram it all into one variable and use that as the second argument.
    That should say the third argument.

    Anything that you want to send as the body of your email must go into the variable that is passed as the third argument to the mail function. It's only as complicated as you want to make it.

    PHP Code:
    $var1 "I'm ";
    $var2 "a ";
    $var3 "sentence.";

    $message_body $var1.$var2.$var3;
    $message_body .= " And I'm another sentence."
    $message_body .= " 123 456 789";
    $to "me@example.com";
    $subject "test message";

    mail($to$subject$message_body); 
    Are you a Help Vampire?


  •  

    Posting Permissions

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