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 "http#mydomain.com" if sSMPT is triggered through the php mail function or "root#mydomain.com" 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)
root=info#mydomain.com
# 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.
# rewriteDomain=info#mydomain.com
# 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 = "user#gmail.com";
$betreff = "Testing Mailserver";
$text = "It seems to work";
$extra = "From:Info <info#mydomain.com>\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 = "user#gmail.com";
$betreff = "Testing Mailserver";
$text = "Seems to work";
$extra = "From: no-reply#example.com \r\n".
'Reply-To: no-reply#example.com '."\r\n" .
"Return-Path: no-reply#example.com\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 http#mydomain.com
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
Try the following adding this to your php script:
$email_message = "Something here";
$email_subject = "a subject";
$email_recipient = "test#example.com";
$email_headers = "From: no-reply#example.com \r\n".
'Reply-To: no-reply#example.com '."\r\n" .
"Return-Path: no-reply#example.com\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_recipient, $email_subject, $email_message, $email_headers);
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.
Related
I have the following config file for msmtp
account default
host SES_HOST
port 587
timeout 5
auth on
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
syslog on
set_from_header on
allow_from_override off
user SES_USERNAME
password SES_PASSWORD
from SES_VERIFIED_EMAIL
php.ini
sendmail_path = /usr/local/bin/msmtp -ti
I want to make sure all emails sent via php use the SES_VERIFIED_EMAIL in the from header so SES does NOT reject the email. I thought setting the from allow_from_override on and allow_from_override off would mean that email send from php with a from header that is NOT SES_VERIFIED_EMAIL would be replaced by SES_VERIFIED_EMAIL so the message will be sent
But I can only send emails via php where the from header is already put in as SES_VERIFIED_EMAIL but I need it to work in all cases. It doesn't appear the from header is being replaced
I want msmtp to override the From header to SES_VERIFIED_EMAIL so it does get sent. I thought the settings above would do it.
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: NOTSESVERIFYED#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Change:
set_from_header on
To:
set_from_header off
Try:
from SES_VERIFIED_EMAIL
rewrite_domain SES_VERIFIED_EMAIL
The rewrite_domain option is used to rewrite the domain part of the From header. This is useful if you want to send mail from a domain that is not your own. The domain part of the From header is rewritten to the value of the rewrite_domain option. The local part of the From header is not changed.
I've got a form page on my website where the user has to enter his email ID. As soon as he does that an email should get triggered to him. I've used the mail() function but the email isn't going through. This is on a remote server. Am I missing out on something? Below is the PHP code that I'm using.
<?php
$to = 'xyz#gmail.com';
$subject = 'Demo mail';
$message = 'This is a demo mail. Please reply to make sure the mail communication is okay.';
$headers = 'From: abc#gmail.com' . "\r\n" .
'Reply-To: abc#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $message, $headers)) {
echo("<p>Email successfully sent!</p>");
} else {
echo("<p>Email delivery failed</p>");
}
?>
The output is Email delivery failed!
What is it that I'm supposed to do apart from this? Thank you in advance!
mail() function relies on email configuration of the server the program is running on. You should take a look at your server email configuration, or use a library in order to hook up with an external SMTP service, like Gmail or one of your email servers. I recommend the Swift email library, which is well known, it's thoroughly tested and has a great community behind:
http://swiftmailer.org/
check php.ini config file for SMTP connection or add ini_set("SMTP", "IP_ADDRESS"); in your script.
you can also wrap your script with a error handler to debug the SMTP connection.
Started off with e-mails not being sent at all, but then I used the "-f" parameter in the function, which then works to send to external addresses (Gmail and Hotmail tested so far) but it won't work for addresses that are on the domain though. Just wondering if it's in the code or is it a problem with the server setup?
if ($Valid == 1) {
$_POST = array_map('strip_tags', $_POST);
$_POST = array_map('stripslashes', $_POST);
$To = "user#domain.ca";
$Subject = "Online Driver Application";
$Body = "All the values of the form that was filled out (removed because there was a lot and it doesn't affect the problem)";
$Headers = 'MIME-Version: 1.0' . "\r\n";
$Headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$Headers .= 'From: Company <info#domain.ca>' . "\r\n";
$Headers .= 'Reply-To: no-reply#domain.ca' . "\r\n";
$Headers .= 'X-Mailer: PHP/' . phpversion();
mail($To, $Subject, $Body, $Headers, -finfo#domain.ca);
echo '<div class="success">Thank You! Your form has been successfully submitted.</div>';
} else {
if ($ErrorMsg != '') {
echo '<div class="error">'.$ErrorMsg.'</div>';
}
Again, unless I have the -finfo#domain.ca in the mail function, e-mails don't get sent out at all.
Thanks.
The additional_parameters parameter (-f or -r) can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option.
The additional_parameters(> 4.2.2) is disabled in safe_mode and the mail() function will expose a warning message and return FALSE when used.
The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from being added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is /etc/mail/trusted-users.
(or, remove sendmail and install postfix (much easier) if still in problem.)
The code seems OK. This is probably something not setup correctly (like PHP.ini not having the SMTP server or a Firewall blocking something). Also, make sure newlines are "\n" in $Body I've seen some mail servers rejecting mails because of this. Using mail directly is always tricky. Try to use a library like Swiftmailer or PHPMailer instead. This way you don't have to worry about how to send HTML, attachments...
this may be a noobish question. I'd like to know if I can send emails from the server that say, domain1.com is associated with, as coming from domain2.com and also having the origin show as coming from domain2.com?
The reason I'd like to do this, is because I have an application I'm developing and would like to send emails from the domain, for example - maildomain.com instead of coming from domain.com
Emails are being sent with php's mail function.
Yes, you can:
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example-two.com' . "\r\n" .
'Reply-To: webmaster#example-two.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
You should set up some things, so the receiver doesn't mark it as spam though:
Set up DNS MX records with low priority for the receiving domain, pointing to sending server
Setup correct reverse DNS entries for sending server
..
The "From" address in an email is entirely arbitrary. As long as you have permission to submit mail to a server's queue, you can put any From address in it that you want. president#whitehouse.gov, julian#wikileaks.org, etc.
To do this with PHP's mail() function, use *$additional_headers*. For example:
$to = "whoever#example.com";
$subject = "This is an example!";
$message = "Hello,\n\nThis is message body.\n\nIsn't that nice?\n\n";
$headers = "From: El Presidente <president#whitehouse.gov>\r\n"
. "X-foo: bar\r\n";
$result = mail($to, $subject, $message, $headers);
Possible? Yes is sure is. See the below example from PHP.net. However, I'm going to put a little piece of fine print here, as I think you might run into some trouble, and I want to make it easier for you in the future. ;) Your current webhost may block this, I've never seen it, but I've heard it can happen. Also, there is a thing called SPF, or Sender Policy Framework, that is a DNS record that you can set to determine what servers can send on your behalf. Many servers that could receive your mail, and especially GMail check for valid SPF. All you have to do is add a TXT record on your name server for domain.com. It should look something like this: v=spf1 mx a:maildomain.com -all. This says any records that have an MX record set up, and the IPs that are resolved from maildomain.com are valid 'non-spam'. Also, you will to fail any other mail origin.
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
If the mail server is an open mail relay then yes, you can send from a different domain. It is of course seen as a vulnerability as spammers can use it to send out junk mail. The configuration of the mail server to get this functionality depends on its platform but you can usually test a server's ability to freely relay messages by telneting to the server on port 25 and doing an ehlo test.
I have an email form that isn't sending out an email to the recipient or a copy to the client. The form can be found at www.kelcos.co.uk/contact and the files associated with this are:
/index.php
/jquery.js
/sendemail.php
/submitform.php
/thanks.php
/verify.php
I have used this form on other websites http://www.bowlesgreen.co.uk/contact/ and http://www.arbortectreecare.co.uk/contact/ and it works fine - the only difference is that these other sites use my usual hosting provider and for the one that won't send I'm working through the clients hosting provider, which I can only presume is what is causing the problem.
I have contacted the hosting and so far we have eliminated a few things such as:
'The limitation to our systems is that the emails sent using scripts will be blocked if they are not going to or coming from an email address setup on the web hosting account. - so I am now sending the form to an a kelcos.co.uk address, but still no joy.
PHP/ASP was originally disabled, but now has been activated
the mail() script is enabled
I would really appreciated any advise any of you could offer.
Thanks
No, http://www.bowlesgreen.co.uk/contact/ doesn't work fine as you said. Firebug reports: POST http://www.bowlesgreen.co.uk/projects/wp/wp-content/themes/bowlesgreen/contactform/sendemail.php 404 Not Found
Your forms are submitting to the wrong URL.
Is Qmail available on the server? Are you setting the headers properly?
Try something like the following:
putenv ("QMAILUSER=myuser");
putenv ("QMAILNAME=My Name");
putenv ("QMAILHOST=mydomain.com");
$headers = 'From: My Name <myname#mydomain.com>' . "\r\n" .
'Reply-To: My Name <myname#mydomain.com>' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$mail_to = 'myemail#myemail.com';
$subject = "Testing email";
$body = "This mail is a test";
mail($mail_to, $subject, $body, $headers);
And see if you receive an email!
try these
http://forum.codecall.net/php-forum/28696-php-contact-form-isnt-sending-out-email.html
http://www.astahost.com/info.php/Php-Send-Email-Problem_t2259.html