Gsuite Email - Why is my SPF is softfail and DMARC fail? - gmail

I am using PHPMailer on GoDaddy to send the email from the GSuite domain email. I did all the configurations according to the Google docs and verified the google._domainkey also,
$mail->IsSMTP();
$mail->CharSet = "UTF-8";
$mail->SMTPDebug = 1;
$mail->Debugoutput = 'html';
$mail->SMTPAuth = false;
$mail->SMTPSecure = 'None';
$mail->Host = "localhost";
$mail->Port = 25;
$mail->Username = "sender#sender.com";
$mail->Password = "********";
$mail->priority = 1;
$mail->addCustomHeader("X-MSMail-Priority: High");
$mail->addCustomHeader("Importance: High");
$mail->addCustomHeader("List-Unsubscribe","<sender#sender.com>");
$mail->addCustomHeader("X-MimeOLE:","Powered by Something.");
$mail->Sender = "sender#sender.com";
$mail->setFrom('sender#sender.com','SENDER NAME');
$mail->addAddress('hello#hello.com','Person');
$mail->Subject = "The subject";
$mail->msgHTML("My email body.");
$mail->IsHTML(true);
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
And tested my configurations with the toolbox.googleapps.com which show everything is fine.
✅ Effective SPF Address Ranges.
✅ Domain should have at least 2 NS servers.
✅ Naked domain must be an A record (not CNAME).
✅ Every name server must reply with exactly the same TXT DKIM records.
✅ Every name server must reply with exactly the same TXT DMARC records.
✅ Every name server must reply with exactly the same CNAME records.
✅ Every name server must reply with exactly the same NS records.
✅ Every name server must reply with exactly the same MX records.
✅ Every name server must reply with exactly the same TXT records.
✅ DKIM authentication DNS setup.
✅ Formatting of DMARC policies.
✅ SPF must allow Google servers to send mail on behalf of your domain.
✅ MX lookup must fit in one UDP response packet.
✅ TXT lookup should fit in one UDP response packet.
But when I send the email from PHPMailer and receive, it shows question mark (?) on the profile image and in the show original it says:
SPF: SOFTFAIL with IP ********.
DMARC: 'FAIL'.
And also getting a gray warning which says:
Be careful with this message The sender hasn't authenticated this message so Gmail can't verify that it actually came from them.
I tried all Google & Stack-Overflow solutions but still no luck.

Related

Feedback form hangs due to PHPMailer

I have a feedback form, this script is filtering and validating data and writing data to the database. At the very bottom, through include, I connected a script with PHPMailer, which sends the text of the feedback form to my mail via gmail smtp.
If I comment out the script connections, then the form is submitted either immediately or after 1 second. With him, he can wait 2-3 seconds.
I submit form data via XMLHttpRequest, remotely. Upon successful submission, the form is reset to zero and the submit button becomes inactive, and via pop-up notifications I display the server's response. So it happened that I managed to press the send button 2-3 times until the script worked and, accordingly, several records were created and several letters were sent to the mail. Is this how it should be or have I configured PHPMailer wrong?
Let me know what data I need to attach. This is my PHPMailer script:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require $_SERVER['DOCUMENT_ROOT'] . '/form/PHPMailer/PHPMailer.php';
require $_SERVER['DOCUMENT_ROOT'] . '/form/PHPMailer/Exception.php';
require $_SERVER['DOCUMENT_ROOT'] . '/form/PHPMailer/SMTP.php';
$mail = new PHPMailer;
$mail->CharSet = 'UTF-8';
$mail->isSMTP();
$mail->SMTPDebug = 0; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
$mail->Host = gethostbyname("smtp.gmail.com");; // use $mail->Host = gethostbyname('smtp.gmail.com'); // if your network does not support SMTP over IPv6
$mail->Port = 587; // TLS only
$mail->SMTPSecure = 'tls'; // ssl is deprecated
$mail->SMTPAuth = true;
$mail->Username = 'mymail#gmail.com'; // email
$mail->Password = 'mypassword'; // password
$mail->setFrom($email, $name); // From email and name
$mail->addAddress('mymail#gmail.com', 'Admin'); // to email and name
$mail->Subject = $subject;
$mail->msgHTML("Message from: \n"."<h3>".$email."</h3>\n"."<h1>".$message."</h1>"); //$mail->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded,
$mail->AltBody = 'HTML messaging not supported'; // If html emails is not supported by the receiver, show this body
// $mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->send();
// if(!$mail->send()){
// echo "Mailer Error: " . $mail->ErrorInfo;
// }else{
// echo "Message sent!";
// }
?>
You're doing some inadvisable things here.
$mail->Host = gethostbyname("smtp.gmail.com");
This sets Host to a literal IP address, and that in turn means that you will never have it match a TLS certificate name. As a result you're having to disable TLS verification, which is never a good thing. If you understand exactly why you're doing this, and what the consequences are, that's fine, but if not, you shouldn't be doing it.
There isn't any error checking in this script. I suggest starting again using the gmail example provided with PHPMailer which is much more careful.
You've discovered why sending to remote mail servers with SMTP during web form processing generally a bad idea: it's too slow, partly by design. The best way to work around this is to install a local mail server (postfix is good) and configure it as a relay to your gmail account – if you search for that you'll find plenty of examples. When that's done, you can submit messages to localhost, it will be more or less instant, and it will take care of queuing, throttling, bounces etc.

DKIM not verified but dns record match key

Strugglign to get DKIM working. currently this is mail-tster result.
https://www.mail-tester.com/test-38w40jo78
im mainly missing the DKIM here is my dns records.
truebud.ca text = "truebud-64839v5873958h3ddrg._domainkey.truebud.ca k=rsa\; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChKyCHHZEkrYfTdcB2VX0nKL8Vhicb+xQsNswOgo5+IK2ipg97VJb+lKAT+jHMXyk4KPTkUUI/8rwa2IfUKsr/BQXy6csNkmM0Y00H5/+QRAYn+ktoRWO1zXvO2sygzCELgGxcj5pHkOd4xLGhTnTpHh7UAjTp" "/swV5E18dpAubQIDAQAB"
truebud.ca text = "v=DMARC1\; p=none"
truebud.ca text = "v=spf1 a mx ip4:216.221.70.222 ~all"
truebud.ca text = "_domainkey.truebud.ca o=~\; r=info#truebud.ca"
and here is my code for phpmailer
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
//use PHPMailer\PHPMailer\Exception;
require 'vendor/phpmailer/src/Exception.php';
require 'vendor/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/src/SMTP.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
$site = 'truebud.ca';
$sitename = 'Truebud';
try {
//Server settings
//$mail->isSMTP(); // Send using SMTP
$mail->Host = '216.221.70.222'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'info#'.$site; // SMTP username
$mail->Password = '[pass]'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('info#'.$site,$sitename);
$mail->addAddress('test-38w40jo78#srv1.mail-tester.com');
$mail->addReplyTo('info#'.$site,$sitename);
$mail->addCC('cc#'.$site);
$mail->addBCC('bcc#'.$site);
// Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Truebud promotion';
$mail->Body = 'wall o' text';
$mail->AltBody = 'wall 'o text';
$mail->AddCustomHeader("List-Unsubscribe: <mailto:unsubscribe#".$site."?subject=Unsubscribe>,<http://".$site."/unsubscribe.php>");
$mail->DKIM_domain = $site;
$mail->DKIM_private = "rsa.private"; //path to file on the disk.
$mail->DKIM_selector = $sitename."-64839v5873958h3ddrg";// change this to whatever you set during step 2
$mail->DKIM_passphrase = "";
$mail->DKIM_identity = $mail->From;
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
Ive been at this for a week. What am i missing?
Their error says:
We were not able to retrieve your public key.
Please ensure that you inserted your DKIM TXT DNS record on your domain truebud.ca using the selector Truebud-64839v5873958h3ddrg.
I can see what's wrong — your DKIM DNS entry is incorrectly formatted.
# dig txt Truebud-64839v5873958h3ddrg._domainkey.truebud.ca
Truebud-64839v5873958h3ddrg._domainkey.truebud.ca. 120 IN TXT "truebud-64839v5873958h3ddrg._domainkey.truebud.ca v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChKyCHHZEkrYfTdcB2VX0nKL8Vhicb+xQsNswOgo5+IK2ipg97VJb+lKAT+jHMXyk4KPTkUUI/8rwa2IfUKsr/BQXy6csNkmM0Y00H5/+QRAYn+ktoRWO1zXvO2sygzCELgGxcj5pHkOd4xLGhTnT" "pHh7UAjTp/swV5E18dpAubQIDAQAB"
You've got the hostname inside the record value - it should start with v=DKIM1, like:
truebud.ca text = "v=DKIM1; k=rsa\; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChKyCHHZEkrYfTdcB2VX0nKL8Vhicb+xQsNswOgo5+IK2ipg97VJb+lKAT+jHMXyk4KPTkUUI/8rwa2IfUKsr/BQXy6csNkmM0Y00H5/+QRAYn+ktoRWO1zXvO2sygzCELgGxcj5pHkOd4xLGhTnTpHh7UAjTp" "/swV5E18dpAubQIDAQAB"
However, while I was testing that I saw you had changed it, so I guess you spotted the same mistake!

Email sending failed (asp.net)

This is a code to send email... It works perfect fine in my computer but doesnt work when i upload this code on godaddy serve.
this is the error iam getting
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 173.194.205.108:587
(you need to download the EASendMail.dll for your particular network frame for this code to work)
SmtpMail oMail = new SmtpMail("TryIt");
EASendMail.SmtpClient oSmtp = new EASendMail.SmtpClient();
// Your gmail email address
oMail.From = "SendersAddress#gmail.com";
// Set recipient email address
oMail.To = "Recieverseaddress#gmail.com";
// Set email subject
oMail.Subject = "Verification Code";
// Set email body
oMail.TextBody = "This is a test code";
// Gmail SMTP server address
SmtpServer oServer = new SmtpServer("smtp.gmail.com");
// Set 25 port, if you want to use 587 port, please change 25 5o 587
oServer.Port = 587;
// detect SSL/TLS automatically
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
// Gmail user authentication
// For example: your email is "gmailid#gmail.com", then the user should be the same
oServer.User = "Sendersaddress#gmail.com";
oServer.Password = "Password";
try
{
Messagebox("start to send email over SSL ...");
oSmtp.SendMail(oServer, oMail);
Response.Redirect("~/Verification.aspx");
}
catch (Exception ep)
{
Messagebox("failed to send email with the following error:");
Messagebox(ep.Message);
}

List-Unsubscribe in header prevents email from being delivered to gmail

I am using phpmailer to send email.
When I add the list-unsubscribe the email gets delivered to all accounts, except gmail. It just gets dropped, it doesn't go into spam, it just never arrives at the gmail account. When I remove the list-unsubscribe, it successfully gets sent to the gmail account.
This is the list-unsubscribe that I am using:
List-Unsubscribe:<http://keepity.com>,<mailto:admin#keepity.com>
This is how its called in phpmailer:
$mail->AddCustomHeader("List-Unsubscribe:<http://keepity.com>,<mailto:admin#keepity.com>");
This is the full function that calls phpmailer. If I comment out the list-unsubscribe then the mail gets delivered to gmail account, otherwise it never arrives. Does anyone know why it would not be delivered?
static function phpmailer_sendmail($mail,$from,$fromAlias,$to,$replyTo,$replyToAlias,$subject,$html,$text) {
require_once (JPATH_COMPONENT.DS.'PHPMailer-master/class.phpmailer.php');
$mail = new PHPMailer(true); // by setting TRUE you enable exceptions
$mail->IsSMTP(true); // SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Mailer = "smtp";
$mail->Host= "xyz"; // Amazon SES
$mail->Port = 465; // SMTP Port
$mail->Username = "xyz"; // SMTP Username
$mail->Password = "xyz"; // SMTP Password
$mail->ClearAllRecipients();
$mail->ClearAddresses();
$mail->ClearCCs();
$mail->ClearBCCs();
$mail->ClearReplyTos();
$mail->ClearAttachments();
$mail->ClearCustomHeaders();
$mail->SetFrom($from, $fromAlias);
$mail->AddReplyTo($replyTo,$replyToAlias);
$mail->Subject = $subject;
$mail->IsHTML(true);
$mail->Body = $html;
$mail->AltBody = $text;
$address = $to;
$addressAlias = $to;
$mail->AddAddress($address, $addressAlias);
$mail->AddCustomHeader("List-Unsubscribe:<http://keepity.com>,<mailto:admin#keepity.com>");
$mail->Send();
}
the function addCustomHeader gets 2 arguments
and the unscribe value format should be
<email_to_unscribe#email.com>, <http://url_to_unscribe.com>
here is an example how it should be called :
$mail->addCustomHeader("List-Unsubscribe",'<admin#keepity.com>, <http://keepity.com/?email='.$address.'>');
I know this is old, but it's ranking well in Google for a search of "List-Unsubscribe" and the provided suggestion isn't quite correct.
PHPmailer addCustomHeader only takes one argument. The double quotes wrap the entire header like this.
$mail->AddCustomHeader("List-Unsubscribe: <mailto:info#example.com?subject=Unsubscribe>, <http://example.com/unsubscribe.php?mailid=1234>");
List-Unsubscribe takes 2 arguments, a mailto: and a URL that can be set up to automatically unsubscribe the email. Of course you can generate the mailid (or whatever you call the GET var) dynamically too.

Signing PHP emails on shared hosting

I am on a shared hosting plan, and when I send emails with PHP, email clients (like Gmail) will add a little via bit to my from field, with my host's domain in there.
So instead of my emails being just from my domain:
From: me#mydomain.com
It's from two domains:
From: me#mydomain.com via host13.myhost.com
Clearly, this is confusing to people receiving email and is poor branding. Since I'm on a shared hosting plan, I don't think I'm likely to have access to the configurations settings of PHP or whatever it uses to mail. Is it possible for me to digitally sign my PHP emails, or is this not possible on shared hosting?
Here is what I'm doing now:
$header = "From: me#mydomain.com";
mail("you#yourdomain.com", "subject", "body", $header);
You can try this, you need to download the PHP Mailer class from Here and your code will be like this:
<?php
include "PHP MAILER CLASS";
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
//$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "example#gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->AddAddress("Reciever Email", "Reciever Name");
$mail->SetFrom('Sender Email', 'Sender Name');
$mail->Subject = "Subject";
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML("Message Body");
$mail->Send();
} catch (phpmailerException $e) {
$e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
$e->getMessage(); //Boring error messages from anything else!
}
?>
The default mail function is at the mercy of your server setup and rarely looks like regular mail to the reciever. You should use a library either SwitfMailer or pear MAIL that can send the mail through your own mail server via SMTP. You can use your normal email account or setup a new one for your web service.

Resources