Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

'mail' from command line for script use - not working. =(

'mail' from command line for script use - not working. =(

'mail' from command line for script use - not working. =(


As part of the logging db project, I need to send PHP-generated email out of one of the Linux machines onto the internet.  I do not want to run an smtp daemon on the linux server, I just want to be able to send a few outgoing emails.  I do not want to run a service and have port 25 listening for connections.

Side note: I am using Sendmail and RedHat 7.1.

I have been playing with the 'mail' command but have not gotten the following line to work - without it error'ing  or prompting me for further information (such as subject line, etc.)

mail("bogus@somedomain.com", "My Subject", "Line 1\nLine 2\nLine 3");

I have even tried that line with a space after the 'mail' command but then it inserts the entire line into the TO: field and prompts me for a subject.  =(

1. Does anyone see what I am doing wrong with this command?

Try not.  Do.  Or do not.  There is no try.

RE: 'mail' from command line for script use - not working. =(

Hi Halfcircles,
If you have sendmail, then you already have an smtp server (used by some of the largest ISPs in the world).  If you have it running,  then it is already listening to port 25.  If you don't have it running, mail can't go out.
Mail is for local mail only and passes everything outbound to sendmail it also receives inbout from sendmail and passes it to your pop3 server on port 110.

RE: 'mail' from command line for script use - not working. =(

Sendmail is installed on the linux server, yes.  Sendmail is *not* running - nor does it need to be running in order to send mail outbound.

i.e. sendmail is stopped (not running)
If I type the following at a command prompt:
"mail user@domain.com" <and hit enter>

I will then be prompted to fill in the subject and body fields - and it will send out the email.

I am really trying to ask if the following command is 'legal' - and if not, how do I fix it so it works.

mail("bogus@somedomain.com", "My Subject", "Line 1\nLine 2\nLine 3");

You see, I am trying to send mail using a 'one-line' command without user intervention.

Many thanks!

Try not.  Do.  Or do not.  There is no try.

RE: 'mail' from command line for script use - not working. =(

ok - now I gotcha.  What you will be doing then is using your ISPs smtp server.  I'm not too familiar with using mail with a script but I might be able to give you a few ideas to work with.  I tried using your script line and got errors also.  First try using the '-n' switch to tell mail not to read the /etc/mail.rc file.  This file contains lines like 'ask' and 'askcc' telling mail to promt for them.  You can also use the '-s' switch to tell mail the next group of text is the subject.  If your subject has spaces (i.e. more than one word), use quotes. That's about the extent of my wisdom .    It seems everthing after the recipients name was also considered another recipient.  Maybe you can download a few scipts that use mail and see how they do it.  I hope you whoop this puppy.  Good luck.  Oh, one more thing.  I got syntax (token) errors when I put everything in braces.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close