1

I have a VPS where I've installed my site files, including the PHP email script that uses the php mail() function inside of the following directory (how my site directory/path is set up):

/var/www/mywebsite.com/html/

*DIRECTORY/PATH STRUCTURE SHOWN IN THE IMAGE BELOW: https://ibb.co/2SDjb8z

And when I installed Postfix, I've configured it to send email through Amazon SES. Postfix has been installed inside of the following directory:

/etc/postfix/

*DIRECTORY/PATH STRUCTURE SHOWN IN THE IMAGE BELOW: https://ibb.co/XF1JFvv

The problem that I'm having is that it will send email from the command line when testing that Postfix has been properly installed along with using the Amazon SES SMTP, BUT my php email script DOESN'T connect from my websites folder directory to Postfix.

How do I connect my php email script to Postfix? Do I need to change directories?

Here is the php mail() function script that I'm using below:

<?php
$to = "MyTestEmailAddress@gmail.com";
$subject = "Another Test!";
$txt = "Hello world!";
$headers = "From: MyEmailAddress@gmail.com" . "\r\n" .
"CC: AnotherTestEmailAddress.com";

mail($to,$subject,$txt,$headers);
?>

Note that the above php script, is the in the file called “email1.php” inside of my website folder. I’m just trying to connect it to Postfix which is located in the “/etc/postfix” directory.

Aaron Esteban
  • 71
  • 2
  • 8
  • 2
    what do you mean by "doesn't connect"? What symptoms are you seeing, exactly? Your code doesn't even check whether `mail()` returns true or false... – ADyson Jan 27 '20 at 16:37
  • P.S. Here's a good general guide to debugging email problems in PHP: https://stackoverflow.com/a/24644450/5947043 – ADyson Jan 27 '20 at 16:40
  • Hi ADyson, and thank you for your support. What I mean is that it doesn't send email from the "email1.php" script that I've referred to above. The script just loads a blank screen. I haven't tried to configure the script to output any errors. I'm just trying to get it to send email, using the Postfix and Amazon SES configuration that I have installed and set up. How do I configure the "email1.php" script to connect to the Postfix configuration, to get it to send email from my main website folder (as mentioned above, where it's currently located)? – Aaron Esteban Jan 27 '20 at 17:18
  • I'd recommend using a wrapper for this sort of thing, it greatly simplifies the process of `sendmail` within php: https://github.com/PHPMailer/PHPMailer – parttimeturtle Jan 27 '20 at 18:31
  • Hi Parttimeturtle! So if I set the PHPMailer folder inside of my /var/www/mywebsite.com/html/ folder, will it automatically detect the Postfix folder and send email through it or will I have to do additional configurations to get it to connect through the Postfix MTA & Amazon SES SMTP? – Aaron Esteban Jan 27 '20 at 18:37

1 Answers1

4

When you installed Postfix it should have created a sendmail command line program.

Locate it and set the path to it in php.ini for the sendmail_path option.

sendmail_path string
Where the sendmail program can be found, usually /usr/sbin/sendmail or /usr/lib/sendmail. configure does an honest attempt of locating this one for you and set a default, but if it fails, you can set it here.

Systems not using sendmail should set this directive to the sendmail wrapper/replacement their mail system offers, if any. For example, » Qmail users can normally set it to /var/qmail/bin/sendmail or /var/qmail/bin/qmail-inject.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Hi Quentin, and thank you for your support. How do I set the path to it in php.ini for the sendmail_path option? What should the line of code look like as for setting the proper path, in the "php.ini" file? – Aaron Esteban Jan 27 '20 at 17:12
  • Also, where do I find the "php.ini" file, in order to edit it? – Aaron Esteban Jan 27 '20 at 17:16
  • Okay, so I've located my "php.ini" file which was found in "/etc/php/7.2/apache2/php.ini" and I set the the "sendmail_path" like so "sendmail_path = /usr/sbin/sendmail". But the email will still not send from my website directory. What else would I need to configure? – Aaron Esteban Jan 27 '20 at 17:47
  • Here's what it looks like after I've edited it. https://ibb.co/CW7bVxw – Aaron Esteban Jan 27 '20 at 17:56