I have been trying to use Office365 SMTP relay for a web server running postfix. I need to be able to send messages from my Office365 domain to other addresses in the domain, so I don't think port 25 anonymous SMTP is going to work.
If I run
echo "testing" | sendmail -fuser#mydomain.com me#mydomain.com
Then the message goes through (provided that user is listed in sasl_passwd)
However if I run a simple PHP script such as this:
<?php
$to = "me#mydomain.com";
$subject = "Test";
$message = "test from PHP";
$from = "user#mydomain.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
Then the delivery is bounced with
550 5.7.1 Client does not have permissions to send as this sender
I have read that the empty from=<> value (which I can see in the logs) is the cause of the problem, but I don't understand how to change that to anything from postfix settings. Am I understanding correctly that postfix relay settings are correct if the command-line works? Is there some other step for PHP configuration that I am missing?
From looking at the log file, it appears as though two messages are generated each time the PHP script is run. One has the correct from address and the other is empty.
Let me know if you need any other information. Thanks in advance.
-Seth
Thanks to this other person (also answering their own question):
https://serverfault.com/questions/147921/forcing-the-from-address-when-postfix-relays-over-smtp/152126#152126
I am just posting this for anyone else who might stumble on my question.
Related
Tried many times but no luck... I don't where the problem. Required help in solving the above code.
//SEND MAIL
$mymail=file_get_contents("mailaddress.txt");
$frommail=file_get_contents('CCmail.txt');
$to = $mymail;
$subject = "User details";
$txt = "<b>USER DETAILS</b>\r\n\r\nName: $fname\r\nEmail: $email\r\nContact no: $mobile\r\nProvince: $city $state\r\n Gender: $gender\r\nComment: $comment\r\n\r\n<b>QUESTION & ANSWERS</b>\r\n\r\nGender: $selectedgender\r\nSleeping Hours: $sleep\r\nWorking Hours: $work\r\nWeight & Height: $weightheight\r\nIllness: $illness\r\nAllergies: $allergies\r\nSweating: $sweating\r\nAge: $age\r\nSpecial Care: $care\r\nSleeping Position: $sleepingposition\r\nLevel Of Comfort: $comfort\r\nPreference: $preference\r\n";
$headers = "From: $frommail" . "\r\n" .
"CC: $frommail";
wp_mail($to,$subject,$txt,$headers);
echo"successfull";
}
}
else{
echo"Not Allowed";
}
?>
For WordPress (or indeed for any software) to send email messages it needs to have access to a Simple Mail Transfer Protocol (SMTP) server somewhere on the Internet.
The best way to do this is to
install a WordPress plugin like WP Mail SMTP. It takes over from php's rudimentary built-in SMTP handler. It also provides a plugin settings screen where you can configure your email settings.
get yourself an account on one of the SMTP services mentioned in the plugin's documentation. I like sendgrid.com for this purpose, because it has a free tier allowing up to 100 messages a day forever.
You could use the SMTP server belonging to your own email provider. But the big providers like gmail and yahoo really don't like automated email systems sending email through them, and they may refuse connections from your WordPress instance. They especially don't like incorrectly formatted email messages: the kind you might send while debugging your application. They're trying to resist attacks from spammers and cybercreeps.
Write and test your code sending only to email accounts under your control (avoiding developer spam to unsuspecting people).
A word to the wise: many countries prohibit "protected health information" -- data about medical patients -- in email messages. It's impossible to guarantee the confidentiality of email due to the way it works.
In the USA it's even illegal for a hospital or doctor to send ANY email to a patient without that patient's consent: the From: and To: fields of the email identify the recipient as a patient of the sender. Respect your patients' confidentiality!
I have to run mail function on laravel with google smtp.gmail.com or default mail() DRIVER only cant use other methods as client requirement but both not working. I tried everything that I can
I tried smtp.gmail.com and default mail() DRIVER both but no result
.env file code
With smtp
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxxx#gmail.com
MAIL_PASSWORD=xxxxxxxx
MAIL_ENCRYPTION=tls
With mail
MAIL_DRIVER=mail
MAIL_HOST=null
MAIL_PORT=null
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Controller code
$template_data = EmailTemplate::getEmailTemplateByID($template->id);
$email_params['verification_code'] = $user->verification_code;
$email_params['name'] = Helper::getUserName($user->id);
$email_params['email'] = $user->email;
Mail::to($user->email)
->send(
new GeneralEmailMailable(
'verification_code',
$template_data,
$email_params
)
);
It's not showing any error just showing success message that you are registered or we send recovery email but no email in inbox
you need to add mail host and mailport as these are requires to send mail.
just go through this link must resolve this issue
https://appdividend.com/2018/03/05/send-email-in-laravel-tutorial/
I've recently moved a Wordpress site from one server to another and I can no longer send mail via SMTP.
There is clearly somesort of network/resolver/credentials problem and I'm trying to debug it, but I've encountered some really unusual behaviour.
I'm looking at the connect method of the SMTP class. If I just try the code as it stands, then the line
$this->smtp_conn = #stream_socket_client(
$host . ":" . $port,
$errno,
$errstr,
$timeout,
STREAM_CLIENT_CONNECT,
$socket_context
);
causes a timeout. However if I add my own member variable eg protected $myvariable; and change the above code to assign the stream socket to $myvariable rather than smtp_conn, there is no time out.
If I check the unaltered code using var_dump on $this->smtp_conn just before trying to open the connection, it is NULL.
I've can't see any other code in PHPMailer which would effect the member variable $smtp_conn and I can't see how changing the name of a variable could stop the timeout.
Can anyone help me to debug this further.
================= EDIT =====================
I've discovered the assignment of $this->smtp_conn to the result of stream_socket_client causes the get_lines method to execute directly. That is, if I place an exit command directly after the assignment of $this->smtp_conn = stream_socket_client, the code in get_lines still runs.
I am sending account activation email from my .net app.
I set the from address to "xyz.support#gmail.com" and from name "xyz" where xyz is the name of the domain i.e. our website.
It was not a problem when we were using Google's SMTP server as I provided credentials to google during sending. But now I am using my own web server's SMTP to send the email.
When I view the activation email in gmail, I get this:
This message may not have been sent by: xyz.support#gmail.com Learn more Report phishing
Is there a way to get rid of this so that gmail and other client don't show this message?
Here is the code:
var smtpClient = new SmtpClient();
var message = new MailMessage();
smtpClient.Host = _config.SMTPServer;
message.From = new MailAddress("xyz.support#gmail.com", "xyz");
message.To.Add("newuser#gmail.com");
message.IsBodyHtml = true;
message.Subject = "Test subject";
message.Body = "Test Body";
smtpClient.Send(message);
Thanks
The domain of the FROM address has to match the domain of the SMTP server that is sending the email, otherwise your message is treated as as spam.
This explains why you avoid the "error" by sending via Google's SMTP server.
The suggestion by IrishChieftain to use SPF helped me, so here is a summary of the steps I did:
1.) First, I also received emails in my GMail inbox that I sent from my sever and that got the "This message may not have been sent by..." warning.
2.) Next, I looked at the source of the email inside GMail (clicke the arrow next to the message and select "Display original"). An excerpt from there was:
Received-SPF: fail (google.com: domain of me#mydomain.com does not
designate 211.113.37.19 as permitted sender) client-ip=211.113.37.19;
So Google directly told me what to do: Add some SPF records in the DNS of my domain "mydomain.com" to get rid of this warning.
3.) Therefore I logged into the control panel of my DNS provider and added two TXT records, something like this:
*.mydomain.com. 180 v=spf1 +a +mx ip4:211.113.37.19 -all
mydomain.com. 180 v=spf1 +a +mx ip4:211.113.37.19 -all
Please note that I entered each line in three separate fields:
One field for *.mydomain.com.
One field for 180 (the TTL, 3 minutes in my example)
One field for v=spf1 +a +mx ip4:211.113.37.19 -all
4.) After that, I waited some time and tried to resend. This succeeded. Google now shows in the original:
Received-SPF: pass (google.com: domain of Received-SPF: pass (google.com: domain of me#mydomain.com designates 211.113.37.19 as permitted sender) client-ip=211.113.37.19;
Please note that I choose the SPF version since the mail server is on a different machine as the web server, so I could not perform the other solution as Mulmot wrote.
There is also an SPF Wizard from Microsoft to correctly generate SPF records. Alternatively, here is yet another SPF generator.
I have a problem on how to send mail on notification while editing or creating any contents in open atrium.
I have followed as mentioned in below link
https://community.openatrium.com/documentation-en/node/28
but was not successful in sending mail to notified user on creating or editing of contents.
And also i wanted to send a mail to user when his credentials is changed or edited.
May can anyone help me in rectifying this issues.
Is your server/PHP enabled to send mails?
Maybe that is not the case and this is why no messages are sent.
In any way you can do a couple of tests to check that out what is wrong. For some, you will need the devel module installed:
Check if your server has the SMTP functionality installed and running (how to check this changes a lot from server to server)
Check if your PHP installation manages to send mail. There are plenty of available scripts to do this on the internet. I C&P one below.
Check if you can send mails with drupal (with the develop module installed, visit http://example.com/devel/php and use the drupal_mail() function.
Change the setting from the devel module and put the mail to "log only": this will show you if Open Atrium is at least trying to send them.
Example PHP script to test mail functionality.
$to = "recipient#example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
}
else {
echo("<p>Message delivery failed...</p>");
}
?>
HTH!
According to the OpenAtrium Installation docs, all you need to do is enable the [standard Drupal cron job]. That worked for me in my OpenAtrium installation. Just to be clear, I did not have to alter php.ini or install the Drupal SMTP module.
Documentation is not realistic. Take a look to this post:
https://community.openatrium.com/issues/node/79
Fixed installing smtp module and letting openatrium mail with PHPMailer.