Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: mail() function with runtime ini_set() for SMTP and SMTP_PORT not working on Linux

I have used a PHP code for Mailing using a SMTP HOST as given below:

        ini_set('SMTP','myserver');
ini_set('smtp_port',25);
$to = $email;
$headers  = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers  .= "From: NO-REPLY<[email protected]>" . "\r\n";
$subject = "Confirmation For Request";
$message = '<html>
                <body>
                    <p>Hi '.$firstname.' '.$lastname.'</p>
                    <p>
                        We recieved below details from you. Please use given Request/Ticket ID for future follow up:
                    </p>
                    <p>
                        Your Request/Ticket ID: <b>'.$ticketID.'</b>
                    </p>
                    <p>
                    Thanks,<br>
                    '.$team.' Team.
                    </p>
                </body>
            </html>';
mail( $to, $subject, $message, $headers ); 

Now When i execute the code in Windows Localhost.. I am succcesfully recieving the mail whereas, If I deply the same code on my Linux setup, I do not recieve anymail, though the mail() function returns true in linux machine as well....

On looking into the phpinfo for both windows localhost and Linux server, for mail parameters I found a single difference,

In Windows I found sendmail_path == "No Value", whereas on linux server it says, "usr/sbin/sendmail -t -i"

Could some one help me to resolve this issue?

NOTE: In windows, its a WAMP setup, whereas Linux is a Dedicated server...

like image 419
Padyster Avatar asked Sep 10 '13 10:09

Padyster


1 Answers

If you're looking to your php.ini there is a short description that

ini_set('SMTP','myserver');
ini_set('smtp_port',25);

This both values are only for Windows. So if you want to send mails over SMTP on linux you have to install postfix for example and build a relay.

https://www.linode.com/docs/email/postfix/postfix-smtp-debian7

Or what is really much easier use a lib that can send SMTP mail over socket or curl like Swiftmailer.

http://swiftmailer.org/docs/sending.html

Thats much easier and its working.

like image 153
René Höhle Avatar answered Nov 03 '22 01:11

René Höhle