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.
Related
I am trying to send an email from localhost, and the program I am using is MAMP. I have looked this up online and done everything written, but this still won't work. The function I have entered in my PHP file to send emails is:
mail(
$admin_email, $messaage,
'Works!',
'An email has been generated from your localhost, congratulations!');
furthermore, I have filled out all the send mail value as shown below:
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=25
smtp_ssl=ssl
auth_username=****#gmail.com
auth_password=*******
hostname=localhost
Obviously - my email and password are filled out using my email and password. Also I have altered the php.ini file as shown:
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;http://php.net/sendmail-path
sendmail_path = C:\Windows\System32\sendmail\ -t -i -f my_email#gmail.com
Can someone tell me where my error is?
You're not going to be able to send via Google's SMTP server because the mail() function doesn't perform SSL or TLS authentication, which is required. See this answer for more information. You should consider using the PHPMailer class instead.
Also, please note that you're using mail() incorrectly. You have
mail(
$admin_email, $messaage,
'Works!',
'An email has been generated from your localhost, congratulations!');
The second argument should be a subject, and the third should be the message. The fourth argument is optional and is supposed to contain extra mail headers:
additional_headers (optional)
String to be inserted at the end of the email header.
This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.
It is not for a plaintext message like you are using. By adding plaintext where a properly-formatted header should be, you are likely to break some servers and some mail readers.
If you are using smtp_port=25you have to change smtp_ssl=none or use this
smtp_port=587
smtp_ssl=tls
Have you changed these settings from your gmail account
Access your email account. Click the Gear Tool > Settings > Forwarding
and POP/IMAP > IMAP access. Click "Enable IMAP", then save your
changes
For check email use these code
<?php
$to = 'myemail#yahoo.com';
$subject = 'Fake sendmail test';
$message = 'If we can read this, it means that our fake Sendmail setup works!';
$headers = 'From: myemail#egmail.com' . "\r\n" .
'Reply-To: myemail#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)) {
echo 'Email sent successfully!';
} else {
die('Failure: Email was not sent!');
}
?>
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.
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...
can someone please help me figure out why this isn't sending? I'm new to PHP.
It's for a contact form on my website. I'm sending from my server (not localhost) and receiving the console message "Mail not sent"
<?php
include 'ChromePhp.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$to = 'me#myemail.com';
$subject = 'Email from Me';
$message = $_POST['email'];
if(mail($to, $subject, $message)){
ChromePHP::log( 'Mail Sent');
}else{
ChromePHP::log( 'Mail Not Sent');
}
}
?>
I realise this question has been asked before, but I can't find an answer that works. Thanks in advance!
You should include header to mail() function, example
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
then insert $headers parameter to mail() function:
mail($to, $subject, $message, $headers);
Without an error message, I can only guess. You probably need to set the SMPT server in your php.ini. You can do that at runtime using ini_set('SMTP', 'your_server_here').
More about the mail configuration here: http://php.net/manual/en/mail.configuration.php
If you don't have one, you can check if your ISP has an open server. ISPs sometimes have open SMTP servers (outgoing servers) and you can find them by looking for instructions on how to set up your mail program (Outlook).
Be careful though, and don't use this for anything but light testing. I can imagine they won't like a lot of spam going through their server.
EDIT: Also, read up on the headers required. I see you're missing a From header, which should result in a warning. See here: http://php.net/manual/en/function.mail.php
When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.
Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.
You should check your mail services, because above PHP code quite true.
You can ask to your hosting provider to activate mail services because some hosting provider does not allow to use mail in default.
When I send mail via PHP's mail() it sends the wrong header information...
$to = 'mypersonal#gmail.com';
$subject = 'the subject';
$message = 'hello, hi :)';
$headers = 'From: Support <support#site.com>' . "\r\n" .
'Reply-To: From: support#site.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
in my gmail it shows
Support via mydedicatedserver.dediprovider.com
How can I configure PHP mail() to send my domain name?
mail() is already sending your domain name.
Gmail sometimes displays that message when Google is not familiar with your server and the hostname of your server does not match the domain name you're sending e-mail from. It's an anti-spam/anti-phishing measure.
Add proper SPF records to your domain. If the server is under your control, try changing its hostname to something that includes your domain name, like server1.site.com. Follow all other advice listed in the link below. Even then, there is no guarantee that Gmail will drop the message right away. In my experience, that message goes away after a while when Google becomes familiar with e-mails from your server and decides that none of them are spam. But Google seems reluctant to disclose exactly what is required, probably because they don't want spammers to get too clever.
See: https://support.google.com/mail/bin/answer.py?hl=en&answer=1311182
Also, the Reply-To: From: header is wrong.