Not able to send Email messages in WordPress - wordpress

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!

Related

Error Sending mail through Gmail SMTP relay [duplicate]

This question already has answers here:
Sending email in .NET through Gmail
(26 answers)
Closed 2 years ago.
I'm working on building a contact form for my new Web site and want to send mail through Google's SMTP relay server (smtp-relay.gmail.com) because I want to set up a "dummy", "no-reply" address from which to send the mail. Also, I tried sending it through the regular SMTP server (smtp.gmail.com) using my own actual Gmail credentials for that account and it got blocked as an insecure app. I'd rather not turn on the "Less secure app access" option (it's not really an option for me anyway because I use 2FA on this account), so this seems like the best way to get there - if I can get it working.
The domain's mail is hosted in G Suite and I've configured the SMTP relay service in the Google Admin Console for my domain as per the instructions in the support article, SMTP relay: Route outgoing non-Gmail messages through Google. I have the relay configured using both the public static IP address of my Web site, as well as the static IP address of the firewall behind which the Web server lies. I configured the relay to accept mail from my domain(s) to allow for the "dummy" address that doesn't actually have a mailbox, and set it to require SMTP Authentication and TLS encryption:
I've set up DNS records for MX, SPF, and DKIM with my domain registrar.
I've waited over 24-hours for the changes to take effect (as per the notification when making the changes in the Google Admin Console)
I've even set up an app password for my Web site to use for my domain e-mail address:
I'm using an ASP.NET (VB) Web site on IIS. My code for sending looks like this:
Dim NewContact As New System.Net.Mail.MailMessage()
With NewContactMessage
.From = New System.Net.Mail.MailAddress("no-reply#mydomain.com")
.To.Add("myaddress#mydomain.com")
.Subject= "TEST MESSAGE"
.IsBodyHtml= True
.BodyEncoding = System.Text.Encoding.UTF8
.Body = "This is a test."
.Priority = System.Net.Mail.MailPriority.Normal
End With
Dim Server As New System.Net.Mail.SmtpClient()
With Server
.Port= 587
.Host= "smtp-relay.gmail.com"
.EnableSsl= True
.Send(NewContactMessage)
End With
However, when I try to submit my contact form, I get an error, Mailbox unavailable. The server response was: 5.7.1 Invalid credentials for relay [X.X.X.X]. The IP address you've:
It looks like there should definitely be more to that actual error message, but it's apparently being truncated somewhere along the way.
I've tried feeding the credentials in the SmtpClient block:
With Server
.Credentials = New System.Net.NetworkCredential("myaddress#mydomain.com", "my_app_password")
.Port= 587
.Host= "smtp-relay.gmail.com"
.EnableSsl= True
.Send(NewContactMessage)
End With
In this case, I get a different error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at. (If I use the credentials with the "default" Gmail SMTP server (smtp.gmail.com), I get the same error.)
According to the Audit Logs, it appears that all of my configuration setting changes have completed. Everything appears to be correct for this to work, but what am I missing?
Just before posting this question, I found this Q&A - Send mail via google app with smtp relay - with the simple fix to my issue: Turn off the Require SMTP Authentication option in the SMTP relay service configuration settings.
Once I disabled that setting and tried again, everything is flowing normally. I suppose I should have figured that out on my own, but according to Google's support article for setting up the SMTP relay (emphasis mine in the first sentence):
In the Authentication section, check one or both boxes to set an authentication method:
Only accept mail from the specified IP addresses — The system only accepts mail sent from these IP addresses as coming from your domains.
Require SMTP Authentication — Enforces the use of SMTP authentication to identify the sending domain. Using this option requires your clients to connect via TLS.
The wording here seems a bit misleading and appears to indicate that you can have both of these options enabled without one "interfering" with the other. As I said, I probably should have figured this out on my own - especially since I'm trying to send from a "dummy" e-mail account - but I guess it just didn't occur to me.
I considered deleting this question, but I had done a fair amount of searching before writing this question up and somehow never ran across that particular post. I'm not sure how I could have missed it, but I'm leaving my question here in hopes that someone else has an easier time of finding this solution in the future.

What `control` settings are valid to send automated emails from Outlook using `sendmailR`?

EDIT: I found a solution. You can find it here. I had to resort to using mailR. I could never get sendmailR to work with the Office 365 services.
I am trying to send a single email using library(sendmailR) to later send daily automated emails to about 500 people. Unfortunately, I'm suck in step 1.
It is vital that I send these emails from my institution's Outlook account. I have no idea what control settings to use in order to successfully send mails from Outlook. I checked a couple of questions but they are either using the gmail SMPT server or they do not specify the control = ... settings they used. For example:
Use sendmailR with Windows
Sending an email from R
This is what I'm working with:
from <- "<myaccount#institution.org>"
to <- "<boss#institution.org>"
subject <- "Hello from R"
body <- list("It's working.")
sendmail(from, to, subject, body,
control = list(smptServer = "oultook.office.365", port = 443))
And I'm getting the following error message:
Error in wait_for(code) :
SMTP Error: 5.7.57 SMTP; Client was not authenticated to send anonymous mail
during MAIL FROM [SN4PR0501CA0061.namprd05.prod.outlook.com]
I believe I'm not specifying the port correctly. The sendmaiLR documentation is not specific enough, but something tells me I should be writing the port as "port 443"or something along those lines.
Does anyone know what controlsettings I should be using?

Email Address Varification Application in ASP.NET

I am getting 555 syntax error in mailfrom
SendData(tcpSocket, string.Format("MAIL From: {0}\r\n", MailFrom));
if (!CheckResponse(tcpSocket, 220))
{
tcpSocket.Close();
return false;
}
is it the problem in my local system because of localhost?
Please help me. I am using this code from below link.
http://www.codeproject.com/Articles/5189/End-to-end-Email-Address-Verification-for-Applicat
Please don't try to implement your own SMTP client, use the one that comes with .NET: System.Net.Mail.SmtpClient.
Many SMTP servers require TLS, for example, which your code does not account for.
Furthermore, for security reasons most mailservers will not reveal if an email address in an RCPT TO line is valid or not. If a system can positively reveal an address exists then it can be used by spam harvesters. Consequently using a dry-run of an SMTP client should only be used to validate an email address (because of the complicated rules regarding valid email addresses). The verification (a separate concept from validation) must be performed manually by requiring the user to respond to an email sent to that address, there is no other way to be sure.

Email sent from web server causes gmail to treat as phishing. How to get rid of this?

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.

Sending email from classic ASP

SOLVED: Two students gave us the wrong emails, and for some reason the script refused to process more if it encountered a wrong email. I am still wondering why is it so !
I am trying to read a bunch of records from a database, and for each record I am creating some text based on some fields of the record and then sending them as email to the email address provided in the record.
The problem is the email gets sent for only about 5-10 records (it varies, once it sent 5 emails, with cc and everything, next day it sent 7).
After this it comes up with the famous error:
error '8004020f'
/sendEmail.asp, line 139
I have researched all around the internet, and I see many have issues with this error, but not the kind that I am having, in which few emails are send and then it stops.
Also, all emails are being sent to the same domain, the official school email of the students.
Any ideas? Any settings that I might want to ask the website hosting guy to change?
Here is the code.
Dim objMail
Set objMail = CreateObject("CDO.Message")
objMail.From= "someEmail"
objMail.To=rstemp("Email")
objMail.Cc = "someEmail"
objMail.Subject = subjecttext
objMail.HTMLBody=tempData
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")= 2
'Name or IP of remote SMTP server
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.*"
'Server port
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
objMail.Configuration.Fields.Update
objMail.Send
set objMail=nothing
tempData = nothing
EDIT: On more debugging, it turns out that when I replace the objMail.To from sending it to each student's email to my own email. It works fine and sends all the emails to me.
Please check first all the Emails is valid and no test email is there. and you can test it with send all emails on same email address for no. of time and can track the problem that is this Email address problem or something else.

Resources