Results 1 to 10 of 20

Thread: Day 12 - Sending Mail From PHP - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Location
    kerala
    Posts
    19,076

    Default unexpected '$body' (T_VARIABLE) error

    Following error showing day_12_ex_3.php
    Parse error: syntax error, unexpected '$body' (T_VARIABLE) in day_12_ex_3.php on line 5

    Missing ( ; ) in
    $fromEmail = $POST['fromEmail']

  2. #2
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by sibichan1 View Post
    Following error showing day_12_ex_3.php
    Parse error: syntax error, unexpected '$body' (T_VARIABLE) in day_12_ex_3.php on line 5

    Missing ( ; ) in
    $fromEmail = $POST['fromEmail']
    Updated the post, hope that will fix the error. Hope everyone can find and fix small errors like this by now.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  3. #3
    Join Date
    Nov 2009
    Location
    kerala
    Posts
    19,076

    Default PHP Email form

    Sender email address not getting in inbox.
    its showing as 'unknown sender'





    in day_12_ex_3.php, i changed the below line

    $fromEmail = $POST['fromEmail'];

    to

    $fromEmail = $_POST['fromEmail'];

    and now its working.


    http://php.flashwebhost.com/sibichan...ay_12_ex_3.php

    PHP Code:

    <?php
    if (isset($_POST['submit'])) {  

      
    $fromEmail $_POST['fromEmail'];   

     
    $body $_POST['body'];  

     
    mail('[email protected]','Message from web site'$body'From: ' $fromEmail);  

      echo 
    'Thank you for contacting us.';} 

    else {   

    echo 

    '<!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">  
    <title>Contact Us</title>
    </head>
    <body>
    <form action="day_12_ex_3.php" method="POST">  
      Email<br>    <input type="text" name="fromEmail"><br>   
     Message<br>  <textarea name="body" cols="30" rows="10"></textarea>  
      <br>    <button type="submit" name="submit" value="submit">Send Mail</button></form>
    </body></html>  
    '
    ;}
    Last edited by Vahaa11; 06-03-2014 at 05:53 AM.

  4. #4
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Add "\n\r" after $fromEmail.

    Find

    PHP Code:
    mail('[email protected]','Message from web site'$body'From: ' $fromEmail); 
    Replace with

    PHP Code:
    mail('[email protected]','Message from web site'$body'From: ' $fromEmail "\n\r"); 
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  5. #5
    Join Date
    Nov 2009
    Location
    kerala
    Posts
    19,076

    Default

    Why need "\n\r" after $fromEmail ?

  6. #6
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by sibichan1 View Post
    Why need "\n\r" after $fromEmail ?
    This is because that field is called Header. 4th parameter in mail() function access many more stuff than just from like mail priority, x-send from and many more. Each line in header need to be separated with "\n\r", this is called, new line + carriage return.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  7. #7
    Join Date
    Nov 2004
    Location
    India
    Posts
    65

    Default

    http://php.flashwebhost.com/stefin/contact.php

    Code:
    <?php
    
    
    if (isset($_POST['submit'])) {
       $fromEmail = $_POST['fromEmail'];
        $body = $_POST['body'];
        mail('[email protected]','Message from web site', $body,
    'From: ' . $fromEmail . "\n\r");
        echo 'Thank you for contacting us.';
    } else {
    
    
    echo
     
    '<!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">  
    <title>Contact Us</title>
    </head>
    <body>
    <form action="contact.php" method="POST">  
    Email<br>    <input type="text" name="fromEmail"><br>   
    Message<br>  <textarea name="body" cols="30" rows="10"></textarea>  
    <br>    <button type="submit" name="submit" value="submit">Send Mail</button></form>
    </body></html>  
    ';}

  8. #8
    Join Date
    Sep 2003
    Location
    india
    Posts
    11,527

    Default

    Code:
    <?php
    if (isset($_POST['submit'])) {
         $formEmail = $_POST['formEmail'];
        $body = $_POST['body'];
        mail('[email protected]', 'Message from Skype', $body , 'From: ' . $fromEmail . "\n\r");  
         echo 'Thanks for Contacting us';
        } else {
        echo
    
    
    
    
    '<!doctype html>
    <html lang="en">
    <head>
     <meta charset = "UTF-8">
    <title> Contact Us </title>
    </head>
    
    
    <body>
    <form action= "form.php" method="POST">
     	Email <br>
    	<input type="text" name="fromEmail"> <br>
    	Message <br>
     	<textarea name="body" cols="30" rows="10"></textarea>
            <br>
            <button type="submit" name="submit" value="submit"> Send Mail </button>
     </form>
    </body>
    </html>';}
    http://php.flashwebhost.com/annie/form.php

Tags for this Thread

Bookmarks

Posting Permissions

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