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 11 of 11
  1. #1
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts

    Getting an error with a simple contact email form

    Im not sure why i am getting this error of:

    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: email

    Filename: views/contact.php

    Line Number: 14
    Could it be that i am using "codeignitor"? I normally use "cake php" but decided to try this out. I use this code all of the time to send the client an email. Can anyone see if i am missing something?

    PHP Code:
    <?php 
    error_reporting
    (0);
    if (
    $_POST["email"]<>'') {  //error line
        
    $ToEmail 'justin@ebby.com'
        
    $EmailSubject 'Vendor Sign Up '
        
    $mailheader "From: ".$_POST["email"]."\r\n"
        
    $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"
        
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"
        
    $MESSAGE_BODY "Name: ".$_POST["name"]."<br>"
        
    $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"
        
    $MESSAGE_BODY .= "Info: ".$_POST["info"]."<br>";
        
    mail($ToEmail$EmailSubject$MESSAGE_BODY$mailheader) or die ("Failure"); 
    ?> 

    <?php 
    } else { 
    ?> 
    <form  method="post" action="/page/display/thanks.php">

    <label for="Name">Name:</label>
    <br />
    <input type="text" name="name" />

    <br/>
    <br />
    <label for="email">Email</label>
    <br />
    <input type="text" name="email" />

    <br />
    <br />

    Information:
    <br />
    <textarea rows="10" cols="40" name="info"></textarea>
    <br /><br/>
    <input name="Submit" type="submit" value="Submit"  />
    </form>
    <?php 
    }; 
    ?>
    Thanks for any help.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Why are you using <>?

  • #3
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts
    to tell you the truth, i went around looking for a simple contact to email php script. I found a few and kind of combined them. Everything seemed fine but i always got this error

    syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
    so i looked around and adding <> seemed to stop it. I am a beginner in PHP so i have no idea why that works. Is there something i should do to avoid this?

    thanks!

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by jcdevelopment View Post
    to tell you the truth, i went around looking for a simple contact to email php script. I found a few and kind of combined them. Everything seemed fine but i always got this error



    so i looked around and adding <> seemed to stop it. I am a beginner in PHP so i have no idea why that works. Is there something i should do to avoid this?

    thanks!
    PHP Code:
    if(isset($_POST['email']) && !empty($_POST['email'])){
    // code.

    the message is a notice and come probably from framework since you have error_reporting(0). Change it to E_ALL to see what's happend.

    Edit: I talk about post #1

    best regards

  • Users who have thanked oesxyl for this post:

    jcdevelopment (03-24-2009)

  • #5
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts
    I tried it and i have no errors, but i have no email sent as well. Not sure what its doing.

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by jcdevelopment View Post
    I tried it and i have no errors, but i have no email sent as well. Not sure what its doing.
    add before error_reporting:
    PHP Code:
    ini_set('display_errors',1); 
    I thought that is enabled, but maybe is not.

    Edit: check to see what you have in $_POST after submit using print_r

    best regards

  • #7
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts
    hmmm.. still no errors or emails... here is what the code looks like now, am i doing it right?

    PHP Code:
    <?php 
    ini_set
    ('display_errors',1);  
    error_reporting(0);
    if(isset(
    $_POST['email']) && !empty($_POST['email'])){
        
    $ToEmail 'justin@ebby.com'
        
    $EmailSubject 'Vendor Sign Up '
        
    $mailheader "From: ".$_POST["email"]."\r\n"
        
    $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"
        
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"
        
    $MESSAGE_BODY "Name: ".$_POST["name"]."<br>"
        
    $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"
        
    $MESSAGE_BODY .= "Info: ".$_POST["info"]."<br>";
        
    mail($ToEmail$EmailSubject$MESSAGE_BODY$mailheader) or die ("Failure"); 
    ?> 

    <?php 
    } else { 
    ?> 
    <form  method="post" action="/page/display/thanks.php">

    <label for="Name">Name:</label>
    <br />
    <input type="text" name="name" />

    <br/>
    <br />
    <label for="email">Email</label>
    <br />
    <input type="text" name="email" />

    <br />
    <br />

    Information:
    <br />
    <textarea rows="10" cols="40" name="info"></textarea>
    <br /><br/>
    <input name="Submit" type="submit" value="Submit"  />
    </form>
    <?php 
    }; 
    ?>

  • #8
    New Coder
    Join Date
    Mar 2009
    Posts
    29
    Thanks
    0
    Thanked 2 Times in 2 Posts
    It'd be better to have email address validation on $_POST['email']?

    Can't see why the mail function's not working otherwise. Debug by commenting out the mail() function and echoing something useful to the screen, make sure the

    PHP Code:
    if(isset($_POST['email']) && !empty($_POST['email'])){ 
    line is doing its job right?

    <Happy to be corrected, I'm new to things but I've just written a mailto script which works>

  • Users who have thanked Mouseman for this post:

    jcdevelopment (03-24-2009)

  • #9
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by jcdevelopment View Post
    hmmm.. still no errors or emails... here is what the code looks like now, am i doing it right?

    PHP Code:
    <?php 
    ini_set
    ('display_errors',1);  
    error_reporting(0);
    if(isset(
    $_POST['email']) && !empty($_POST['email'])){
        
    $ToEmail 'justin@ebby.com'
        
    $EmailSubject 'Vendor Sign Up '
        
    $mailheader "From: ".$_POST["email"]."\r\n"
        
    $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"
        
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"
        
    $MESSAGE_BODY "Name: ".$_POST["name"]."<br>"
        
    $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"
        
    $MESSAGE_BODY .= "Info: ".$_POST["info"]."<br>";
        
    mail($ToEmail$EmailSubject$MESSAGE_BODY$mailheader) or die ("Failure"); 
    ?> 

    <?php 
    } else { 
    ?> 
    <form  method="post" action="/page/display/thanks.php">

    <label for="Name">Name:</label>
    <br />
    <input type="text" name="name" />

    <br/>
    <br />
    <label for="email">Email</label>
    <br />
    <input type="text" name="email" />

    <br />
    <br />

    Information:
    <br />
    <textarea rows="10" cols="40" name="info"></textarea>
    <br /><br/>
    <input name="Submit" type="submit" value="Submit"  />
    </form>
    <?php 
    }; 
    ?>
    PHP Code:
        $mailheader "From: ".$_POST["email"]."\r\n"
        
    $mailheader .= "To ".$ToEmail."\r\n"
    and echo $mailheader to see how it look.
    seems ok. mail return true or false, check if is true.

    best regards

  • #10
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Check to see if the mails being sent to!
    PHP Code:
    if(mail($to$subject$body$add_headers){
    echo 
    'Job Done!';
    }else{
    echo 
    'Error Sending Mail!';

    obviously change the $var names to your actual variable name.

  • Users who have thanked rafiki for this post:

    jcdevelopment (03-24-2009)

  • #11
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts
    Thanks for all of the help, but i was able to look around and CI has some built in form stuff... here was my ending code, which i placed in thanks.php

    PHP Code:
    <?php
    error_reporting
    (0);
    $to "info@twpstudio.com";
    $subject "TWP Studio Contact";
    $body $_POST['Name']."\n ".$_POST['email']."\n";
    $body.= "\n".$_POST['info'];

    if (
    mail($to$subject$body)) {
      echo(
    "");
     } else {
      echo(
    "<p>Message delivery failed...</p>");
     }
    ?>


  •  

    Posting Permissions

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