0

When trying on Windows, it is pretty simple. I have this code in the body of a PHP file:

$to = "synewaveltd@gmail.com";
$headers = 'From: synewavecomplaints@gmail.com' . "\r\n" .
    'Reply-To: ' . $_POST['email'] . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
$fullText = "Complaint from : " . $_POST['email'] . "\r\n" . "Name : " .
    $_POST['fullName'] . "\r\n" . $_POST['mainText'] . "\r\n";
mail($to, $_POST['subject'], $fullText, $headers);

And I have this sendmail.ini file:

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=synewavecomplaints@gmail.com
auth_password=XXXXXXXXXX
force_sender=synewavecomplaints@gmail.com

And basically, what I want to do is send an email from an account called synewavecomplaints@gmail.com to a different account called synewaveltd@gmail.com, where the first email has a password. On Windows, this works.

Now on Linux, there is no sendmail.ini file that comes with LAMPP. I have been browsing all over everywhere for ways I can go around this, like this, but whatever I try, does not work. I even tried to use Postfix using steps from here, but it didn't work either.

I realise that these guides may just be wrong because of how old they are, but I cannot find any recent guides to how to do this. Can anyone tell me how this can be made possible on linux?

ENBYSS
  • 819
  • 1
  • 10
  • 22

1 Answers1

0

I couldn't find a way using Postfix or Sendmail, but I DID find a way using SSMTP.

First install SSMTP: sudo apt-get install ssmtp on ubuntu.

Then, change the configuration files as such:

/etc/ssmtp/ssmtp.conf:

root=username@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=gmail.com
hostname=username
UseSTARTTLS=YES 
AuthUser=username@gmail.com
AuthPass=password
FromLineOverride=YES

/etc/ssmtp/revaliases:

root:username@gmail.com:smtp.gmail.com:587
localusername:username@gmail.com:smtp.gmail.com:587

php.ini [the relevant sendmail part anyway]:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP=smtp.gmail.com
; http://php.net/smtp-port
smtp_port=587

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/ssmtp -t

After doing all of this, everything worked perfectly.

ENBYSS
  • 819
  • 1
  • 10
  • 22