Reputation: 31
I am having issues with my sSMTP setup. It is working fine for sending e-mails, i am receiving them, but it completely ignores my "From: " header! The from address is always "[email protected]" if sSMPT is triggered through the php mail function or "[email protected]" if triggered through an ssh session logged in as root. So i am thinking it always uses the current user and uses that as the "From: " address.
Now i know that you can set FromLineOverride=YES
to allow to use your own From address, i have set that in my sSMPT config, but that doesn't work. It's just ignoring that completely.
Here's my Setup:
sSMTP config:
# The user that gets all the mails (UID < 1000, usually the admin)
[email protected]
# The mail server (where the mail is sent to), both port 465 or 587 should be acceptable
mailhub=mydomain.com:587
# The address where the mail appears to come from for user authentication.
# [email protected]
# i have tried this function above in different ways, doesnt change anything...
# The full hostname
hostname=mydomain.com
# Use SSL/TLS before starting negotiation
UseTLS=Yes
UseSTARTTLS=Yes
# Username/Password
AuthUser=info
AuthPass=password
# Email 'From header's can override the default domain?
FromLineOverride=YES
php Script to test the Mail function:
<?PHP
$empfaenger = "[email protected]";
$betreff = "Testing Mailserver";
$text = "It seems to work";
$extra = "From:Info <[email protected]>\r\n";
// i have tried "From: Info..." with a space inbetween From: and Info.
if(mail($empfaenger, $betreff, $text, $extra)) {
echo 'E-Mail sent';
}
?>
So i get no errors, the mail get's through, the Mailserver is running on my local machine and sees the mails, and i can confirm the mailserver does not change the address it's sent from, he just takes what he gets from sSMTP.
What am i doing wrong?
Cheers
Edit: Tried the following as suggested by DannySMc
<?PHP
$empfaenger = "[email protected]";
$betreff = "Testing Mailserver";
$text = "Seems to work";
$extra = "From: [email protected] \r\n".
'Reply-To: [email protected] '."\r\n" .
"Return-Path: [email protected]\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($empfaenger, $betreff, $text, $extra)) {
echo 'E-Mail versendet';
}
?>
Still does not work. I still see the mail coming from [email protected]
Upvotes: 0
Views: 2086
Reputation: 1187
sSMTP is a popular choice as a simple sendmail replacement for php mail relay in docker containers. If anyone comes across this question because they are using sMTP with Docker containers and cannot get the from header to appear correct in php emails then I recommend moving to msmtp. It is easy to install and use in the standard php docker images.
Upvotes: 0
Reputation: 31
I could not resolve this issue. If anyone else is having this issue, the only thing you can try is FromLineOverride=YES
if that's not working, you're pretty much screwed.
I for one, has changed over from sSMTP to regular sendmail, which is working like a charm.
Cheers
Upvotes: 1
Reputation: 27
Try the following adding this to your php script:
$email_message = "Something here";
$email_subject = "a subject";
$email_recipient = "[email protected]";
$email_headers = "From: [email protected] \r\n".
'Reply-To: [email protected] '."\r\n" .
"Return-Path: [email protected]\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_recipient, $email_subject, $email_message, $email_headers);
Upvotes: 0