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

Thread: PHP Mail

  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts

    PHP Mail

    Dear Friends,

    I am getting problem during sending email. Before the same code was working. But now i am receiving this error.

    Notice: Undefined variable: fname_field in E:\Sites\Single5\starlinks\webroot\mailer.php on line 6

    Notice: Undefined variable: headers in E:\Sites\Single5\starlinks\webroot\mailer.php on line 6

    Notice: Undefined index: message in E:\Sites\Single5\starlinks\webroot\mailer.php on line 12

    Notice: Undefined index: lastname in E:\Sites\Single5\starlinks\webroot\mailer.php on line 13

    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in E:\Sites\Single5\starlinks\webroot\mailer.php on line 31

    My php mail script is below please have a look.

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

        
    $to "yasir.jamal.co.cc"
        
    $subject "From DSR Website";
        
    $headers.= "From: $fname_field\r\n";
        
    $fname_field $_POST['firstname'];
        
    $lname_field $_POST['lname'];
        
    $city $_POST['city'];
        
    $occupation $_POST['occupation'];
        
    $email_field $_POST['email'];
        
    $message $_POST['message'];
        
    $option $_POST['lastname'];
        
    $comment $_POST['comment'];
        
    $telephone $_POST['telephone'];
        
    $mob $_POST['mobile'];
        
    $dropdown $_POST['interstedin'];
        
        
    $body "
        First Name: $fname_field\n
        Last Name: $lname_field\n
        E-Mail: $email_field\n
        Intersted In: $dropdown\n
        City : $city\n
        Occupation : $occupation\n
        Telephone : $telephone\n
        Mobile : $mob\n
        Message: $comment\n"
    ;
            
        if (
    mail($to$subject$body$headers)) {
        
    header ("Location: http://www.yasirjamal.com/Email sent.html");
        }
         
        } else {
        echo 
    "blarg!";
    }
    ?>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    They are notices not errors.
    PHP Code:
    <?php
    if(isset($_POST['submit'])) {

        
    $fname_field $_POST['firstname'];
        
    $lname_field $_POST['lname'];
        
    $city $_POST['city'];
        
    $occupation $_POST['occupation'];
        
    $email_field $_POST['email'];
        
    $message $_POST['message'];
        
    $option $_POST['lastname'];
        
    $comment $_POST['comment'];
        
    $telephone $_POST['telephone'];
        
    $mob $_POST['mobile'];
        
    $dropdown $_POST['interstedin'];
        
        
    $body "
        First Name: $fname_field\n
        Last Name: $lname_field\n
        E-Mail: $email_field\n
        Intersted In: $dropdown\n
        City : $city\n
        Occupation : $occupation\n
        Telephone : $telephone\n
        Mobile : $mob\n
        Message: $comment\n"
    ;
        
        
    $to "yasir.jamal.co.cc"
        
    $subject "From DSR Website";
        
    $headers "From: $fname_field\r\n";
       
        if (
    mail($to$subject$body$headers)) {
        
    header ("Location: http://www.yasirjamal.com/Email sent.html");
        }
         
        } else {
        echo 
    "blarg!";
    }
    ?>
    That should take care of the first two notices. Those variables weren't defined yet when you tried to use them. As to the message and last_name notices it means those items didn't post from you form. Make sure you have inputs in your form with name="message" and name="last_name".

    The warning you get about stmp means you need to enable sendmail in your php.ini file.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Dear friend,

    i am new to php. i dont no how to set smtp. Now i am gegting only 1 error brfore i am getting 6 error.

    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in E:\Sites\Single5\starlinks\webroot\mailer.php on line 29

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Are you hosting a site on your own system or do you have a shared host that you are using?
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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