Ravi Singh
Ravi Singh

Reputation: 441

Can't send php mail from AWS linux machine

I've written following code in php in my AWS linux machine, however it can't send emails

    $to = "[email protected]"; // E-mail address of reciever
    $subject = "Test Subject"; // Subject of email
    $body = "Hi All, <br><br> This is the test email <br><br>Thank You!";
    $header = 'From: [email protected]';

    if(mail($to, $subject, $body, $header)) {
            echo "Email sent successfully!";
    } else {
            echo 'Email send Failed';
    }

The email sending like above always fails. Following is my setting of php.ini

[mail function]
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail -t -i
SMTP = "my smtp server address"
smtp_port = 25

Interestingly, if I send email using following command, it is successfully received

echo "hello" |sendmail -s -v "test" [email protected] 

Can someone please help and advise, what could be causing mail function to fail?

Thanks in Advance.

Upvotes: 1

Views: 1409

Answers (1)

Ravi Singh
Ravi Singh

Reputation: 441

Fixed it by adding "Smart" relay host in /etc/mail/sendmail.cf file.

Following are the steps I took

sudo vi /etc/mail/sendmail.cf       

Search for DS and updated the file like below

#"Smart" relay host (may be null) 
DSsmtp.myserver.local

Upvotes: 1

Related Questions