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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    373
    Thanks
    39
    Thanked 0 Times in 0 Posts

    Unhappy PHP Mail Problem!

    Hello, I am creating a website of mine, and have included a contact form in it! I am having problems when sending an email to test it. Below are my codes including validation and HTML:

    HTML Codes

    form action="#" method="post">
    <p>Your full name (Required):</p>
    <p><input type="text" size="35" placeholder="Your name here..." name="name"/></p>
    <p>Subject (Required):</p>
    <p><input type="text" size="35" placeholder="Subjecte..." name="subject"/></p>
    <p>Your email address (Required):</p>
    <p><input type="text" size="35" placeholder="Your email address..." name="email"/></p>
    <p>Your message (Required):</p>
    <p><textarea cols="66" rows="8" name="comments"></textarea></p>
    <input class="submit" type="submit" value="Send" name="submit"/>
    <input class="submit" type="reset" value="Reset"/>
    </form>

    PHP Codes

    <?php
    if ( $_SERVER['REQUEST_METHOD'] == "POST" ) {
    $fname = htmlentities($_POST['name']);
    $subj = htmlentities($_POST['subject']);
    $emailaddr = htmlentities($_POST['email']);
    $message = htmlentities($_POST['comments']);
    //Check if the form is submitted
    if (isset($_POST['submit'])) {
    if (empty($fname) || empty($emailaddr) || empty($subj)|| empty($message)) {
    echo 'All fields must be filled!'.'<br/>';
    return false;
    }
    elseif (filter_var($fname, FILTER_VALIDATE_INT)) {
    echo 'Name must not be numbers'.'<br/>';
    return false;
    }
    elseif (!filter_var($emailaddr, FILTER_VALIDATE_EMAIL)){
    echo 'Invalid email'.'<br/>' ;
    return false;
    }
    else {
    mail("angel.ali201111@yahoo.com", "$subj",
    $message, "From:" . $emailaddr);
    echo "Thank you for using our mail form";
    }
    }
    }
    ?>

    The error I am having is this:

    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 C:\xampp\htdocs\softwareportfolio\contact.php on line 44
    Thank you for using our mail form

    I am on local host, and I want to test it on localhost itself, so please help me! Thank

  2. #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,280
    Thanks
    6
    Thanked 49 Times in 49 Posts
    You need to set up the smtp details in your php.ini file

  3. #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    373
    Thanks
    39
    Thanked 0 Times in 0 Posts
    Can you help me for that? Please, I am still learning PHP.

  4. #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,280
    Thanks
    6
    Thanked 49 Times in 49 Posts
    In your c:\xampp\apache\bin\php.ini file, around line 700:
    Code:
    [mail function]
    ; For Win32 only.
    SMTP = localhost
    smtp_port = 25
    
    ; For Win32 only.
    ;sendmail_from = me@example.com
    Change SMTP to your ISP’s server and sendmail_from to your email address on the mail server.

  5. Users who have thanked Nightfire for this post:

    angelali (02-20-2012)

  6. #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    373
    Thanks
    39
    Thanked 0 Times in 0 Posts
    You ARE GREAT DUDE...YES it is working now... Now I can test my form. By the way, do you think by using "return false" in my codes above when validating is OK? Give me your opinions on my codes above...


 

Tags for this Thread

Posting Permissions

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