#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Issues with mail function


    I am having issues receiving an email from my code. I am not sure what I am doing wrong. Any help would be great!!! Thanks in advance!!

    PHP Code:
              elseif (!$_POST['level']) { $mes12='Please select a Level Of Training';}  else {  echo " Thank you $_POST[fname] !! Your registration has been submitted!!".$sendEmail;   } }  if(isset($_POST['submit'])) {  // validate a phone number if(preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/", $_POST['phone']));   // $phone is valid    else echo $mes8= 'invalid phone number';    if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {   // The email address is not valid echo $mes11= 'invalid email entered';}}  $sendEmail=    $to = 'someone@email.com'; $subject= 'Registration from $fname';  $fname= $_POST['fname']; $lname= $_POST['lname']; $email= $_POST['email']; $street_address= $_POST['$street_address']; $city= $_POST['city']; $state= $_POST['state']; $zip_code= $_POST['zip_code']; $phone= $_POST['phone']; $department= $_POST['department']; $level= $_POST['level'];    $message=<<<EMAIL 'My name is '$fname' . '$lname' , my email is '$email' .  My address is '$street_address' . '$city' . , '$state' . '$zip_code' .   My phone number is '$phone'. I work for '$department' and my level of training is '$level'.' EMAIL;   mail ($to, $subject, $message); 

    let me know if you need any more of the code.

    Moderator's Note: PHP tags fixed by Nilpo. There are two different buttons on the editor: one is for pasting code samples, the other is for pasting references to php.net. It's a little confusing. I've also removed your email address for security. Be careful posting sensitive information in your code samples.

    You have some syntax and spacing issues, here's what I think you're looking at.

    PHP Code:
        elseif (!$_POST['level']) {
            
    $mes12='Please select a Level Of Training';
        } else {
            echo 
    " Thank you $_POST[fname] !! Your registration has been submitted!!".$sendEmail;
        }
    }

    if(isset(
    $_POST['submit'])) {
        
    // validate a phone number
        
    if(preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/"$_POST['phone']));
            
    // $phone is valid
        
    else echo $mes8'invalid phone number';

        if (!
    filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
            
    // The email address is not valid
            
    echo $mes11'invalid email entered';
        }
    }

    $sendEmail=
    $to 'someone@email.com';
    $subject'Registration from $fname';
    $fname$_POST['fname'];
    $lname$_POST['lname'];
    $email$_POST['email'];
    $street_address$_POST['$street_address'];
    $city$_POST['city'];
    $state$_POST['state'];
    $zip_code$_POST['zip_code'];
    $phone$_POST['phone'];
    $department$_POST['department'];
    $level$_POST['level'];

    $message=<<<EMAIL 'My name is '$fname' . '$lname' , my email is '$email' .  My address is '$street_address' . '$city' . , '$state' . '$zip_code' .   My phone number is '$phone'. I work for '$department' and my level of training is '$level'.' EMAIL;
    mail ($to$subject$message); 
    Last edited by Nilpo; December 13th, 2013 at 05:16 PM.
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    please review your post before you submit it. I'm glad that you're one of the few people who managed to find the code formatting buttons. Unfortunately, it didn't quite work out, as you can see. Paste the code and then manually wrap it in [ PHP ] tags (without the spaces).

    There are actually several issues with your code:

    • You haven't investigated the problem. This makes it pretty much impossible for us to help you. Remember: We don't have access to your server, we can't check it ourselves.
    • You're using mail() directly. This is a very bad idea, because there are a lot of mistakes you can make -- like forgetting the From header. In the 21st century, there's really no reason for fumbling with low-level mail stuff. We have modern mailer libraries like PHPMailer.
    • You've probably turned off your error reporting. Otherwise, you would be getting an error message about the missing From header. Always turn your error reporting on and up. Otherwise, you're flying blind. Maybe the program crashes long before it even reaches this snippet.
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Php Freelance Web development
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 1999
    Location
    chennai , tamil nadu , India
    Posts
    60
    Rep Power
    16
    Originally Posted by acarder
    I am having issues receiving an email from my code. I am not sure what I am doing wrong. Any help would be great!!! Thanks in advance!!

    Code:
    		  elseif (!$_POST['level']) { $mes12='Please select a Level Of Training';}  else {  echo " Thank you $_POST[fname] !! Your registration has been submitted!!".$sendEmail;   } }  if(isset($_POST['submit'])) {  // validate a phone number if(preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/", $_POST['phone']));   // $phone is valid    else echo $mes8= 'invalid phone number';    if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {   // The email address is not valid echo $mes11= 'invalid email entered';}}  $sendEmail=    $to = 'webmaster@ottawa-glandorfems.org'; $subject= 'Registration from $fname';  $fname= $_POST['fname']; $lname= $_POST['lname']; $email= $_POST['email']; $street_address= $_POST['$street_address']; $city= $_POST['city']; $state= $_POST['state']; $zip_code= $_POST['zip_code']; $phone= $_POST['phone']; $department= $_POST['department']; $level= $_POST['level'];    $message=<<<EMAIL 'My name is '$fname' . '$lname' , my email is '$email' .  My address is '$street_address' . '$city' . , '$state' . '$zip_code' .   My phone number is '$phone'. I work for '$department' and my level of training is '$level'.' EMAIL;   mail ($to, $subject, $message);

    let me know if you need any more of the code.
    Have you echoed debug statements to find out whether the control structures work properly ?

    Also try sending out a FROM address to the mail command.
    Chris, Developer, Chrisranjana.com
    Chennai, Tamil Nadu, India.
    Php Programmers
  6. #4
  7. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,250
    Rep Power
    1469
    Your first major problem is in this line:
    PHP Code:
    if(preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/"$_POST['phone'])); 
    That semi-colon should be throwing an error.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  8. #5
  9. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Nope. A single semicolon is an empty statement. In this case, it's a very weird workaround to skip the if part.

    @acarder: You realize that you can also negate conditions, right? If you wanna do something in case a condition x is false, you simply write

    PHP Code:
    if (!$x)
    {
        
    // do something

    Please wipe this "if (...);" from your memory. This is totally unnecessary, confusing as hell and very error-prone (you can easily overlook that tiny semicolon).
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  10. #6
  11. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,250
    Rep Power
    1469
    Originally Posted by Jacques1
    Nope. A single semicolon is an empty statement. In this case, it's a very weird workaround to skip the if part.
    I just tested it in 5.3.3, 5.4.14, and 5.5.6. It causes a parse error that halts all output to the browser. I don't have time to double check, but it appears to be a completely empty response. Removing the ; causes the script to execute normally.

    Test code:
    PHP Code:
    <?php
    ini_set
    ('display_errors''On');
    error_reporting(E_ALL);

    echo 
    "start";

    if (
    == 0) ;
        echo 
    "if";
    else
        echo 
    "else";

    echo 
    "finish";
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  12. #7
  13. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    That's not what acarder wrote down. His/her code is this:

    PHP Code:
    <?php

    if (true)
        ;
    else
        echo 
    'foo';
    The if part contains nothing but an empty statement. Yours, however, also has a second statement. This would require braces:

    PHP Code:
    <?php

    if (true)
    {
        ;
        echo 
    "if";
    }
    else
        echo 
    "else";
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  14. #8
  15. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,250
    Rep Power
    1469
    I see what you're saying.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!

IMN logo majestic logo threadwatch logo seochat tools logo