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 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    67
    Thanks
    20
    Thanked 1 Time in 1 Post

    PHP Error in mail()

    I have this to enable somone to send a message to someone.
    PHP Code:
    <?php    


    $from
    =$_POST['email_from'];
    $to=$_POST['email_to'];
    $subject=$_POST['subject'];
    $message=$_POST['message'];

    mail($to,$subject,$message,$from); 
    ?>
    The error message my site is giving me is
    Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/a5461089/public_html/action.php on line 6

    any help
    Last edited by UltimateCoder; 02-01-2012 at 04:02 PM.

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    You forgot a single quote.

    PHP Code:
    $to=$_POST[email_to]; 
    Change to this

    PHP Code:
    $to=$_POST['email_to']; 
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    You'd have found it yourself if you had used the [PHP][/PHP] tags to wrap your code, like
    PHP Code:
    <?php    


    $from
    =$_POST['email_from'];
    $to=$_POST['email_to];
    $subject=$_POST['
    subject'];
    $message=$_POST['
    message];

    mail($to,$subject,$message,$from); 
    ?>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    tangoforce (01-31-2012)

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,338
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Quote Originally Posted by abduraooft View Post
    You'd have found it yourself if you had used the [PHP][/PHP] tags to wrap your code, like
    PHP Code:
    <?php    


    $from
    =$_POST['email_from'];
    $to=$_POST['email_to];
    $subject=$_POST['
    subject'];
    $message=$_POST['
    message];

    mail($to,$subject,$message,$from); 
    ?>
    Well said. How ironic is it that 'UltimateCoder' can't see these things?

    @'UltimateCoder': You should also be using mail() inside an if() conditional to test that it is accepted by sendmail.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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