Unable to send email from GoDaddy hosted php site - phpmailer

I have tried the solutions from the top 10 stack overflow questions and other resources found online before posting my question here;
I have a php site that's hosted on GoDaddy that's trying to send emails to an Office365 (same defect presents when sending to my gmail though). When originally developed 3 years ago, it would send emails no problem, sometime last year it stopped sending emails.
The original code that used to work
$admin_email = "email#domain.com";
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$message = 'FROM: ' . $email . "\r\n" . $message;
mail($admin_email, "New Message", $message, "From:" . $admin_email);
I also tried using PHPMailer with all manner of options.
These two don't error but I never get the email.
$mail = new PHPMailer;
$mail->Host = "relay-hosting.secureserver.net";
$mail->Port = 25;
$mail->SMTPDebug = 0;
$mail->SMTPSecure = "none";
$mail->SMTPAuth = false;
$mail->Username = "";
$mail->Password = "";
$mail->SMTPDebug = 0;
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->ssl = false;
$mail->authentication = false;
And this one throws SMTP -> ERROR: Failed to connect to server
$mail = new PHPMailer;
$mail->SMTPDebug = 2;
$mail->IsSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
All are sent with
$mail->From = $from;
$mail->FromName = $admin_email;
$mail->AddAddress($email);
$mail->Subject = "New Message";
$mail->Body = $message;
$mail->IsHTML(true);
$mailresult = $mail->Send();
I have also made sure the domain has the following txt records
NETORGFT1413837.onmicrosoft.com
v=spf1 include:spf.protection.outlook.com -all
v=spf1 include:secureserver.net -all
Yes I checked junk/spam folders
The regular php mailer mail($to,$subject,$message,"From:email#address.com"); sends to gmail junk folder doesn't reach Office365 account

The regular php mailer mail($to,$subject,$message,"From:email#address.com"); sends to gmail junk folder doesn't reach Office365 account
I believe the reason this goes to your junk folder in Gmail is because emails sent via PHP's mail() function through GoDaddy are not authenticated. I also tried to utilize SPF records to resolve this, but it was unsuccessful.
Here's a workaround that you might be interested in if you have a Gmail account.
Requirements:
Gmail account, XAMPP or similar local web server, PHPMailer library
(tutorials on how to use XAMPP and PHPMailer are abundantly available online)
Instructions:
Go to "Settings" in your Gmail account. Under "Accounts and Import,"
add "youraccount#domainyouown.com" in the "Send Mail As" section.
In your PHP script (using the PHPMailer library), replace the credentials in the following lines of code with your Gmail credentials and the account you'd like to send from:
$mail->Username = 'username#gmail.com';
$mail->Password = 'yourpassword';
$mail->setFrom('youraccount#domainyouown.com', 'Your Name');
$mail->addReplyTo('youraccount#domainyouown.com', 'Your Name');
Added benefits of this method:
Emails are authenticated. I spent quite a while trying to achieve this via GoDaddy, to no avail. This removes the "possible spam" notification that is sometimes present with emails sent through hosting server relays...
Emails are sent faster. For whatever reason, the emails I sent via GoDaddy using PHP's mail() function took a few minutes to go through. Gmail takes seconds.
Copies of the emails you send actually show up in your Gmail "Sent" folder. This was also something that I could not achieve via GoDaddy, and I was told by customer support that this is a limitation of the service.

Related

Google apps bounces emails sent from nodemailer, but gmail receives them fine

I've set up some google apps mailing groups, but emails from nodemailer to the groups are always getting 'bounced' (but no bounce-back email).
Individual gmail addresses receive the same nodemail fine. The admin email log looks like this for successful email to individual gmail user address. The email headers from the successful email show no issues (eg no spf failures).
The groups do receive emails from external users (including from the same address nodemailer uses) when sent through the gmail web client, so it it isn't a group permission issue. Successful emails to the group yields an admin log like this.
The group is set to forward all spam to users.
Nodemailer is using a gmail account, and the GApps are using a Google domain hosted address, so it shouldn't be an issue with routing or conflicting servers
What am I missing here?
This was resolved by reconfiguring the 'from' field in the nodemailer message.
// Nodemailer ignores the bad `from` value (not a valid email)
// Nodemailer sends with from ==''
// This gets bounced by google group addresses
var msg = {
from: "System",
to: "usergroupaddress#gmail.com,
subject: "Your generated email",
text: "Hello user",
html: "<p>Hello user</p>"
};
I had thought 'from' would define the name displayed on the email. It didn't do that, but it didn't cause any problems either for most email recipients. But google groups was bouncing those emails.
Nodemailer was just leaving 'from' as blank (rather than using my dummy string). Apparently this field must be a valid email address. Set it to an email address, and nodemailer will include it in the message envelope, which google groups will then stop bouncing.
// Nodemailer accepts and forwards the valid `from`
// google groups address will accept the email
var msg = {
from: "system#myserver.com",
to: "usergroupaddress#gmail.com,
subject: "Your generated email",
text: "Hello user",
html: "<p>Hello user</p>"
};
The google apps email also hints at this: emails with an empty 'from' envelope have a blank 'sender' in the google apps email log search. But as soon as I corrected nodemailer, the 'sender' started populating in email log search, and google stopped bouncing the emails. See the email log here.

gsuite mail with phpmailer

I set up my site registration form with phpmailer and gsuite. email is working perfectly. but I getting this notifications top of the register page after registration. what should I do for this?
It looks like you have enabled SMTP debugging. Check your configuration for the below.
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = 2; //Alternative to above constant
PHPMailerSMTP Debugging

Anonymous register an account, will send mail to notify the person in charge

I have facing some difficulty on changing principal : as "Anonymous" in the email during sending an email.
My system is an online system that allow user to register their account, then Admin will just need to click the register button to register their staff in their organization.
For my understanding, Anonymous is a default account in domino system for "outsider" whoever accessing their server / website.
below is my sample coding:
var web = setdoc.getItemValueString("InternetAddress");
var maildoc:NotesDocument = database.createDocument()
maildoc.replaceItemValue("Form", "Memo");
maildoc.replaceItemValue("Subject","Request for Email Account By Applicant);
session.setConvertMime(false);
var stream = session.createStream();
stream.writeText("<html><body>");
stream.writeText("<p>Dear " + "department reviewer" + ",</p>");
stream.writeText('<p>Kindly review this request by '+document1.getItemValueString('Name')+" on "+I18n.toString(#Today(), 'dd/MM/yyyy')+ ",</p>");
stream.writeText("</body></html>");
var body = maildoc.createMIMEEntity("Body");
body.setContentFromText(stream, "text/html;charset=UTF-8", 1725);
stream.close();
maildoc.closeMIMEEntities(true);
session.setConvertMime(true);
maildoc.replaceItemValue("SendTo",document1.getItemValue("Dep_rev"));
maildoc.send();
Attached will be sample photo of my email:
Is there any way to change the Anonymous name to other name?
You are using the current session to send the mail. Therefore the sender is anonymous.
You have several options:
Use sessionAsSigner to get hold of the database and create your mail document from there. This should change the sender
Set the From and Principal fields to the name of the sender. You must include the Domino domain name at the end of the Principal field (sender#company.com#dominodomain)
Set the From and Principal fields and copy the mail directly to mail.box on the server.

How to send and receive emails in mailgun (configured for a subdomain) from the root domain

Mailgun recommends creating DNS (TXT, MX,..) records for a subdomain, but states sending and receiving with the root domain is possible by later configuration. I created all necessary steps for mail.example.com at my registrar and at Mailgun (adding a domain, setting up routes, etc.).
I can now receive and send emails to the configured example#mail.example.com.
What do I have to change now to be able to send and receive at example#example.com?
What are the necessary changes at the registrar, in mailgun, and in my smtp settings at gmail (for sending from gmail via mailgun)?
Thank you very much!
If you configure Mailgun for a subdomain, you can send emails from your main domain passing a proper to variable. For instance, using Node.js + nodemailer + nodemailer-mailgun-transport:
var nodemailer = require('nodemailer'),
mg = require('nodemailer-mailgun-transport'),
auth = { api_key: 'foobar', domain: 'mail.example.com' },
nodemailerMailgun = nodemailer.createTransport(mg({ auth: auth }));
nodemailerMailgun.sendMail({
from: 'helloworld#example.com',
to: 'recipient#domain.com',
subject: 'Hey you, awesome!',
text: 'Mailgun rocks, pow pow!'
}, someCallback);
Or you can read about other methods of sending through an API in their docs. Anyway, even if your Mailgun is configured for a subdomain, you can send email from your main domain.
However (!) your MX records are configured for your subdomain, and hence you can only receive emails there. To be able to receive email to your main domain, add your main domain in Mailgun's control panel, e.g. not mail.example.com, but example.com, and make an according configuration in your DNS control panel for this main domain, example configuration for DigitalOcean's DNS for example.com (not subdomain):
TXT # v=spf1 include:mailgun.org ~all
TXT krs._domainkey k=rsa; p=MIGfM...blablabla
CNAME email mailgun.org.
MX 10 mxa.mailgun.org.
MX 10 mxb.mailgun.org.
Keep in mind, that Mailgun does not have mailbox functionality, it can only forward incoming emails, if you have an appropriate rule set. Most people delegate their main domain's MX records to a more manageable ESP, like Gmail. You can only have one set of MX records for a domain, so you have to choose, either Gmail, or Mailgun.
You need to use mailgun-js for this
Require mailgun-js from npm
var Mailgun = require('mailgun-js');
2.Set options for mailgun. i.e. apiKey and domain.
var options = {
apiKey: 'YOUR_API_KEY',
domain: 'YOUR_DOMAIN'
};
Instantiate mailgun with these options.
var mailgun = new Mailgun(options);
Send email after setting required parameter for it.
var data = {
//From email
from: '',
// Email to contact
to: 'To Email address',
// CC email
ccTo: 'CC address if any'
// Subject
subject: 'Mail subject',
// Email msg
html: 'email message or html'
};
// Send email
mailGun.messages().send(data, callbackFunction() {
});
I've only been using Mailgun a short time, but I can help with what I've learned so far.
Your DNS records can be setup for Mailgun or a third party like Gmail. I don't think they will use both. I'm not sure what that would do to the routing, because it would not know where to go.
For your Mailgun subdomain, you used mail.example.com with email address example1#mail.example.com. Mine is running, but I did not create email addresses like that at all. My email formats are still example1#example.com.
I am going to paste this in from an email I received, and edit it to match your provided example:
It looks like you have set the MX records for the root domain, example.com, however the domain you are using with Mailgun is mail.example.com. You will need to change the hostname from example.com to mail.example.com for these to route correctly.
As Mailgun does not have mailboxes, receiving email with Mailgun requires using a subdomain with MX records pointing to Mailgun as well as using our Routes functionality. A good way to understand Routes is as a sophisticated filtering and forwarding mechanism. With Routes, you can either:
forward the incoming email to another environment for storage (such as an email address or an endpoint on your server
store a message temporarily (for up to 3 days) and retrieve it using the Messages API
stop a message from being processed (i.e. dropping certain messages instead of forwarding or storing them)
If you're trying to use Django's Anymail package to send Mailgun email from a subdomain, you need to send the email using the EmailMultiAlternatives object and specify the Email Sender Domain like so:
from django.core.mail import EmailMultiAlternatives
msg = EmailMultiAlternatives("Subject", "text body",
"contact#example.com", ["to#somedomain.com"])
msg.esp_extra = {"sender_domain": "mg.example.com"}
msg.send()

Preserving Email Subject & Email Message from actual Template when sending via Custom Button in Salesforce

I would like to preserve the Email Subject & email Message that are defined on the Docusign Template and send those vs sending generic email subject & message when sending a document via Custom Button in Salesforce? Below is my button code
{!REQUIRESCRIPT("/apex/dsfs__DocuSign_JavaScript")}
var DST='<Docusign Template Id>';
var LA='0';
var OSO = 'Send';
var CRL = 'Email~{!Fulfillment__c.Primary_Contact_Email__c};Role~Client;FirstName~ {!Fulfillment__c.Primary_Contact_First_Name__c};LastName~{!Fulfillment__c.Primary_Contact_Last_Name__c}';
var CCRM='Client~Client';
window.location.href = '/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID='+eSignatureNotSent.Id+'&DST='+DST+'&LA='+LA+'&CRL='+CRL+'&OCO='+OCO+'&CCRM='+CCRM;
I think Docusign is using Default Email Subject and Default Email Message defined in the Admin settings in Salesforce. I do not want to send it as all the work is done when building templates in Docusign.
If you leave the Default Email Message blank in the Admin settings, it will grab the contents of the Template Email Message.
The API has a hard requirement to define an email subject through the request. Currently because Salesforce uses the API, it has to follow this guideline.
My best advice is making a custom button that defines the Email subject that you'd like for each workflow that you may have.

Resources