Sending mail from the server

Discussion in 'Web Design and Development' started by Fromethius, Aug 6, 2008.

  1. Fromethius macrumors member

    Joined:
    Jun 26, 2008
    Location:
    Pennsylvania
    #1
    I cannot find any scripts online that work with my web server.

    The web server has a built in utility for sending mail but it forces you to use their ugly contact forum, and the perl file is a bloated mess that none of us can begin to edit.

    We don't care about anti-spam or anything. We already have the contact forum set up. We just need a simple 10 to 20 line perl file that can send an email to our webmaster.

    After looking for scripts all day and night and testing around 20 or so, this still is not working. I've tried everything. There must be a mail server set up because the built in one sends the mail, but we need something simpler.

    All the websites are saying not to use sendmail because it's bloated, and are saying to use this script instead of this one, etc. but we're not sure which to use or even if it is set up.

    Thanks for any help.
     
  2. Me1000 macrumors 68000

    Me1000

    Joined:
    Jul 15, 2006
    #2
    If you have PHP set up on your server the mail function is pretty straight forward.

    Code:
    <?php
         mail('you@yourdomain.com','subject', $_POST['message']);
    ?>
    
    That would send the email to your address provided you configured it. Then the field in your form would be called "message" (hence the $_POST variable array using 'message')
     
  3. Fromethius thread starter macrumors member

    Joined:
    Jun 26, 2008
    Location:
    Pennsylvania
    #3
    PHP is not set up, I believe. We need to use perl scripts and the such.
     
  4. Me1000 macrumors 68000

    Me1000

    Joined:
    Jul 15, 2006
    #4
    I doubt php is not setup unless you specifically know it is turned off for some reason, (or consequently not installed)... but I cant really help you with perl as it is pretty much gone the way of the dodo...

    however a quick google search turned this up,
    http://www.cyberciti.biz/faq/sending-mail-with-perl-mail-script/

    which looks pretty straight forward.
     
  5. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #5
    I wouldn't say Perl has gone the way of the dodo. Myself and a number of my co-workers still use it.

    Anyways, have you tried the obvious thing and ask your web host what they allow? That would be the simple approach.
     
  6. Fromethius thread starter macrumors member

    Joined:
    Jun 26, 2008
    Location:
    Pennsylvania
    #6
    Yes, we're using networksolutions as a host and (domain provider?).

    They don't specify (or at least I couldn't find) whether or not they support php and upon creating a phpinfo() file to test it, it doesn't display it, which leads me to believe they do not support it.

    I used the same phpinfo file for my web server on my macintosh and it showed right up.

    Perhaps we have a lower service package? Maybe it was never configured? Maybe they just don't support it?

    I don't know, but I really want to use php because it seems so much simpler than perl (which I could not get to work at all yet!, including your article) and I actually know php.
     
  7. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
  8. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #8
    On any UNIX-like system you can send mail with just one line. See the "mail" man page for details. But basically it goes like this

    Code:
    mail -s "example subject line" someone@myplace.com < filename.txt
    Then from Perl, PHP, Ruby or compiled C code or whatever, you send the above line to be executed by the shell. In Perl you'd just say "system foobar" to send the comand foobar to the shell.

    Read the mail man page.
     
  9. Fromethius thread starter macrumors member

    Joined:
    Jun 26, 2008
    Location:
    Pennsylvania
    #9
    Figured it out.

    The problem was due to our domain still being on a Windows box. I had to call customer support and have all the emails and the domains moved to a Unix box.

    Now PHP is working properly as defined in the phpinfo file. However, when I use the mail function, the mail is still not sent to me.

    I called customer service again and they didn't know. They said I might have to find my own sendmail executable and reference it, but shouldn't they have included it?

    Either way, I'm one step closer but still no e-mail.
     
  10. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #10
    YES, they should!!!!

    On that Unix server, there are traditionally one of two MTA's, either sendmail or exim. Sendmail is the most common, Exim is arguably a little more secure depending on who you ask (I agree).

    Go into the Unix shell and simply type in "sendmail -bp" or "exim -bpa" and see if either one exists. Those commands actually dump the mail queue, demonstrating if they're working properly.

    If you can't find the MTA that way, this means the path environment isn't setup properly (probably) to run daemons without specifying path so perform one more simple search of each to double check:

    "locate sendmail | grep bin" or
    "locate exim | grep bin"

    That searches for each and includes in the output any binary paths meaning that's where the deamon lives. Traditionally for each it's in /usr/sbin but this is how you find out for sure.

    Once you have the proper path to the proper MTA (i.e. "/usr/sbin/sendmail") then run your phpinfo() page again and see what's set for the "Configuration File (php.ini) Path" variable. That''s the config file for PHP showing you the full path (usually /etc/php.ini) to the php.ini file.

    Edit the php.ini file and set the variable "sendmail_path" accordingly:

    (example path, use your own)

    If MTA is sendmail: /usr/sbin/sendmail -t -i
    If MTA is exim: /usr/sbin/sendmail -t

    Note: Exim has a sendmail alias and doesn't need the -i parameter

    Also set smtp_port=25 (the most common SMTP port)

    Save php.ini

    Restart the web server, and that should remedy things.

    If not, contact tech support and tell them the MTA isn't working or PHP can't access it and ask them to debug the above settings. If they tell you they don't have an MTA or you can't access it, drop them and find another host!!!!! heh

    -jim
     
  11. Fromethius thread starter macrumors member

    Joined:
    Jun 26, 2008
    Location:
    Pennsylvania
    #11
    Thanks, after creating a php.ini file in the cgi-bin directory with these lines:

    sendmail_path = /usr/sbin/sendmail -t -i
    smtp_port = 25

    It now works.
     

Share This Page