SMTP on linux

DevilWAHDevilWAH Posts: 2,997Member ■■■■■■■■□□
If I want to set up a simple SMTP relay on linux that can be used by PHP for sending emails. What is the simplest way to achive this?

The system will not need to recive emails, just act as a realy to allow various websites to send out admin mails. For example wordpress.

Do i need to install a complete mailserver solution, or is there a simpler way to achive this?

I keep reading that phpmail() works by default, but this has never been the case for me.

All I want is a simple solution, the full blown email set up is going to come later. I was thinking I could jsut install something like postfix and do some basic config.

Devil
  • If you can't explain it simply, you don't understand it well enough. Albert Einstein
  • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.

Comments

  • NightShade03NightShade03 Posts: 1,383Member ■■■■■■■□□□
    You are correct Postfix is the way to go. Postfix will allow you to have SMTP functionality without the need for receiving mail as well. You can then use PHP mail functions to send out mail. Just a note to make sure that you do a little basic security for Postfix so that it doesn't end up being an open relay for spammers. Their website has a decent walk through to get you going in about 10 minutes.

    Here is a sample of PHP code in case you need it (it was from a helpdesk web application that I wrote).
    function helpdesk_email($name, $dept, $pri, $prob){
    
            $to  = '[email protected]';
            $sub = 'New Ticket Submitted';
            $message = '
                    <html><table><tr><td>Name: '. $name .'</td></tr>
                                             <tr><td>Dept: '. $dept .'</td></tr>
                                             <tr><td>Priority: '. $pri .'</td></tr>
                                             <tr><td>Problem: '. $prob .'</td></tr>
                              </table>
                </html>
                ';
    
            $headers = "From: [email][email protected][/email]\r\n";
            $headers .= "Content-type: text/html\r\n";
    
            mail($to, $sub, $message, $headers);
    
    }
    
  • DevilWAHDevilWAH Posts: 2,997Member ■■■■■■■■□□
    You are correct Postfix is the way to go. Postfix will allow you to have SMTP functionality without the need for receiving mail as well. You can then use PHP mail functions to send out mail. Just a note to make sure that you do a little basic security for Postfix so that it doesn't end up being an open relay for spammers. Their website has a decent walk through to get you going in about 10 minutes.

    Here is a sample of PHP code in case you need it (it was from a helpdesk web application that I wrote).
    function helpdesk_email($name, $dept, $pri, $prob){
     
            $to  = '[email protected]';
            $sub = 'New Ticket Submitted';
            $message = '
                    <html><table><tr><td>Name: '. $name .'</td></tr>
                                             <tr><td>Dept: '. $dept .'</td></tr>
                                             <tr><td>Priority: '. $pri .'</td></tr>
                                             <tr><td>Problem: '. $prob .'</td></tr>
                              </table>
                </html>
                ';
     
            $headers = "From: [EMAIL="[email protected]"][email protected][/EMAIL]\r\n";
            $headers .= "Content-type: text/html\r\n";
     
            mail($to, $sub, $message, $headers);
     
    }
    

    Ok i can't give you more rep (system don't allow it) but cheers for the pointers, all up and working now :)
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Chris:/*Chris:/* Posts: 658Member
    You are correct Postfix is the way to go. Postfix will allow you to have SMTP functionality without the need for receiving mail as well. You can then use PHP mail functions to send out mail. Just a note to make sure that you do a little basic security for Postfix so that it doesn't end up being an open relay for spammers. Their website has a decent walk through to get you going in about 10 minutes.

    Agreed!
    Degrees:
    M.S. Information Security and Assurance
    B.S. Computer Science - Summa Cum Laude
    A.A.S. Electronic Systems Technology
  • NightShade03NightShade03 Posts: 1,383Member ■■■■■■■□□□
  • earweedearweed Posts: 5,192Member ■■■■■■■■■□
    DevilWAH wrote: »
    Ok i can't give you more rep (system don't allow it) but cheers for the pointers, all up and working now :)
    I got him for you DevilWAH icon_wink.gif
    No longer work in IT. Play around with stuff sometimes still and fix stuff for friends and relatives.
  • PashPash Posts: 1,601Member ■■■■■□□□□□
    earweed wrote: »
    I got him for you DevilWAH icon_wink.gif

    Make that two of us.
    DevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me.
  • TechJunkyTechJunky Posts: 881Member
    I think its what you are more comfortable with.

    I myself perfer Sendmail just because I have set them up since 1999.
Sign In or Register to comment.