Jump to content

Setting up PHP mail() function on new server


Recommended Posts

Hi there,

I'm kind of new to the world of setting up dedicated servers so would appreciate some advice on how to set up the mail () function in my PHP.ini on a Linux server.

Is there a generic path that I need to use in order to allow the mail function to work in the scripts?

We do have a mail server set up, the address of which being "mail.companyname.com" ... do I need to insert that into the ini file somwhere instead?

Any help would be REALLY appreciated.

Thanks,
Link to comment
Share on other sites

Is your mail server on the same machine?

All you need do is setup an smtp daemon. Id'e recommend ssmtp as its real simple to configure. Im not sure what distro your using so I wont go into details but, install ssmtp, then open the configuration file (should be /etc/ssmtp/ssmtp.conf or simular) and view the examples.

ssmpt will set itself up as a replacement for sendmail (sendmail is alot more difficult to configure), ie it will create soft links making it look like sendmail. Then you away.

Hope this helps.
Link to comment
Share on other sites

Thanks loads for the reply

[quote]Is your mail server on the same machine?[/quote]

The mail server I mentioned above is on a different machine. The dedicated server we're renting is only accesible by remote access. Am I right in assuming that the dedicated server won't send mail without the mail server?

At the moment, sendmail_path in the php.ini is set to [b]/usr/sbin/sendmail -t -i[/b], which seems to be the default suggested in various articles I've read on Google but it's still not working.
Link to comment
Share on other sites

  • 3 weeks later...
You can specify a diffrent mail/smtp server to use in the php script, although i forget how to do it.  All you need to do in the ini script make the standard mail() comand is enabled.  (by default it is).

As thorpe said though it is simpler just to set up a basic smtp server on the host.  Is very important though to ensure that the local smtp server only allows localhost connections, else you may find your self blacklisted, (allowing to much spam relaying etc).
Link to comment
Share on other sites

  • 3 months later...
Hello Friends,

Iam very new to LAMP installtion,
I have congifured the sendmail and tested using cmd and it is sending the mail but when i send the mail from php with simple mail() funcion it is not sending any mail but it says mail sent.

Can anyone please help me out in this. ?

Warm Regards
Link to comment
Share on other sites

Firstly a friendly word of advice: Dont post your real email address in forums like this!  You may want to eddit it out of your preious post. Sort of thing that spamers scan for, and before you know it your bombarded with gunk! . . . . .

Try this small change and see if it makes any diffrence:

[code]
$success = mail("youremail@domain.com","Subject","Content");
if ($success)
{
  echo "mail sent...";
}
else
{
  echo "unable to send mail";
}
[/code]

The above will however not tell you that the message has been sent, just that it has been sent to the server so you have to look a little deeper ie the logs.

If your using sendmail (the 'out of the box' standard) unable to diliver problems are offten sent strait to your root mail box.  From the comand line, login as root and type: "mail". If its set up you should get a list of messages appear.  The hit enter and have a read.  to exit just hit "q" twice then enter again.  Could be a usefull diagnosting!

Failing that try (again as root)

[quote]ps axvw | grep sendmail[/quote]

and post us the output

Shout if none of that made sence!  Oh . . . and can you tell us what linux you are using.

Engoy!
Link to comment
Share on other sites

Hello Oliver,

I have tried with your code and also typed the following command on cmd "ps axvw | grep sendmail" and found the below output

[root@Mstore ~]# ps axvw | grep sendmail
5143 ?        Ss    0:00      0  704  8252 2224  0.3 sendmail: accepting conn
ections
5151 ?        Ss    0:00      0  704  7172 1636  0.2 sendmail: Queue runner@0
1:00:00 for /var/spool/clientmqueue
6881 pts/2    S+    0:00      0    71  4532  644  0.0 grep sendmail


Regards
Link to comment
Share on other sites

Ok, so that shows that Sendmail is setup and running.  Next thing to do would be to look in the logs.  They should be in  /var/log/ and called something like mailog.  Have a look in this and see what it shows.  Will say wheter it tried to deliver, did deliver, or if the messages are not in there then its not getting them!

Link to comment
Share on other sites

  • 2 months later...
1) Log onto the machine's terminal, and run 'tail -f /var/log/maillog'

2) Run the PHP script

3) Look for errors from tail.  If you do not see errors, look at the PHP error_log file, defined in /etc/php.ini

4) Look at http://www.php.net , and type in 'mail' on the top right of the page to find examples of proven ways to use mail()
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.