Can't send e-mail via php

Discussion in 'PHP' started by ycc, Aug 2, 2007.

  1. #1
    Hello,

    thanks for good help last time here :) I am new with PHP so please advice me on anything.

    I use Ubuntu/Linux 7.04, apache2, php5. I have a small home network behind a linksys router. Ordinary php pages work OK.

    I have forwarded port 25 in my router to this computer. (I don't have an external domain-name connected to this server, I just call it from the outside with IP-number.)

    I tried this (that I copied from the web: about.com and replaced the address): ;)

    <?php
    $to = "my_address@domain.com";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";
    if (mail($to, $subject, $body)) {
      echo("<p>Message successfully sent!</p>");
     } else {
      echo("<p>Message delivery failed...</p>");
     }
    ?>
    Code (markup):
    I activate the code by entering into the browser:
    http://127.0.0.1/~username/my_email_script.php
    Code (markup):
    It replies:
    Message delivery failed...
    Code (markup):
    And, of course, the mail does not arrive.

    Since I am completely new with the subject, maybe there is something, some external factors that have to be present to enable mailing? Some factors that I am (sorry) completely unaware of ?? :eek:

    Greatful for advice :)
     
    ycc, Aug 2, 2007 IP
  2. ycc

    ycc Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Problem solved by installing mailserver (Postfix).
    Sorry for this thread. :eek:
     
    ycc, Aug 2, 2007 IP
  3. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #3
    Just to let you know that you don't have to forward port 25 to the computer unless you want to receive mail. You should setup your smtp setting in your php.ini file to send out mail.
     
    exodus, Aug 2, 2007 IP
  4. ycc

    ycc Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for your comments :) Forwarding port 25 also seems to make the web-server unreachable?

    etc/php5/apache2/php.ini looks like this (probably not good at all since I use Ubuntu/Linux?):
    [mail function]
    ; 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 =
    
    ; 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 =
    Code (markup):
    (The setting up of the postfix server seems to be well covered in this document: http://www.postfix.org/BASIC_CONFIGURATION_README.html#syntax )

    If there are any advice on how to continue, please let me know. The server can now send e-mail, but must definitely, in due course, be able to receive e-mail. So I don't understand how to forward port 25. Forwarding port 25 seems to interfere with the webserver. (The web-server is located on the same computer as the mailserver and thus port 80 will also be forwarded to that machine.)

    My network is so far very simple and, as I see it, no special considerations have to be made.

    I am greatful for any advice how to continue. Sorry if thread is going off topic.
     
    ycc, Aug 3, 2007 IP