Results 1 to 4 of 4

Thread: PHP Mail Help

  1. #1
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default PHP Mail Help

    I'm trying to learn how to send email using PHP. Here is the code:

    Code:
    <?php
    
    if(isset($_GET["sub"]))
    {
    	
    $to = "blaaaah@gmail.com";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";
    $headers = "From: sender@example.com\r\n" .
        "X-Mailer: php";
    if (mail($to, $subject, $body, $headers)){
      echo("<p>Message successfully sent!</p>");
     } else {
      echo("<p>Message delivery failed...</p>");
     }
    
    }
    
    ?>
    Here are the settings I have in my php.ini :

    Code:
    ; For Win32 only.
    SMTP = localhost
    smtp_port = 25
    
    ; For Win32 only.
    ;sendmail_from = me@example.com
    
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    sendmail_path = "D:\XAMPP\xampp\sendmail\sendmail.exe -t"
    
    ; Force the addition of the specified parameters to be passed as extra parameters
    ; to the sendmail binary. These parameters will always replace the value of
    ; the 5th parameter to mail(), even in safe mode.
    ;mail.force_extra_parameters =
    And finally here is the error I'm getting:

    Code:
    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 D:\XAMPP\xampp\htdocs\practice\test.php on line 13

    I don't understand how all this stuff works or what I need to do to fix it. Help is appreciated, thanks!
    What is obvious to you might not be to another.


    My Site

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    I'm experiencing the same thing here at the company.

    The best thing for you is to ask what's your SMTP server, and replace highlighted:
    Code:
    ini_set('SMTP','SMTP.MYSITE.COM');
    ...add this code on the first line of your PHP code.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    Thank you for the reply rangana. I'm trying to do this locally though, so do I need to have my own mail server set up or something?
    What is obvious to you might not be to another.


    My Site

  4. #4
    Join Date
    Nov 2008
    Posts
    58
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Default

    Yes you will need a mail server.

    The easiest way to get a complete server up and running is to set up a virtual server (see vmware.com) You can download a complete web server with email/apache/php from http://www.vmware.com/appliances/directory/370 (look around the virtual appliance market place for more)
    Using Vmware server or vmware player you can run these virtual machines.

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
  •