Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DKIM failes when I add an AltBody #3057

Closed
julesbl opened this issue May 22, 2024 · 4 comments
Closed

DKIM failes when I add an AltBody #3057

julesbl opened this issue May 22, 2024 · 4 comments

Comments

@julesbl
Copy link

julesbl commented May 22, 2024

Problem description

phpMailer 6.8.1, php v7.4
If I send the test email with just a HTML body it works fine, if I send with an AltBody as well I get a DKIM error

Code to reproduce

	$this->emailer = new PHPMailer(true);
	if(ENVIRONMENT == 'development'){
		$this->emailer->SMTPDebug = SMTP::DEBUG_SERVER;
	}
	$this->emailer->isSMTP();
	$this->emailer->Host = $this->config->smtp_server;
	$this->emailer->SMTPAuth = true;
	$this->emailer->Username = $this->config->smtp_username;
	$this->emailer->Password = $this->config->smtp_password;
	$this->emailer->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
	$this->emailer->Port = $this->config->smtp_ssl_port;
	$this->emailer->isHTML(true);

	$this->twig = service('twig');

	$content = [
		'title' => 'Test email',
		'company_name' => 'Routastic',
	];
	$email = $this->twig->render('emails/test.twig.html', $content);
	$text = strip_a($email);
	try {
		$this->emailer->setFrom($this->config->admin_email, 'Routastic admin');
		$this->emailer->addAddress($email);
		$this->emailer->addReplyTo($this->config->admin_email, 'Routastic admin');

		$this->emailer->Subject = 'Test Email';
		$this->emailer->Body = $email;
		$this->emailer->AltBody = $text;
		$this->emailer->send();
	}catch (\Exception $e){
		trigger_error('Failed to send test email: '.$e->getMessage(), E_USER_WARNING);
		return new Error('Failed to send test email');
	}
	return true;

Debug output

image

@XL-2000
Copy link

XL-2000 commented May 23, 2024

To make use of DKIM, you need to configure PHP to do so.
Normally done by setting all needed settings $this->emailer->DKIM_*
(where * are the actual settings like domain, selector, identity, private_key, etc)

Since your code does not set any DKIM instructions, it is logical DKIM is unsigned.

I can not believe it is true that DKIM is working for you if you only set the HTML Body. Maybe your SPAM checker does not raise an error, but it will absolutely not be DKIM signed given your current code

@julesbl
Copy link
Author

julesbl commented May 23, 2024

Its configured as part of the mail sending service and is beyond my remit.
The strange thing is https://dkimvalidator.com thinks its ok but https://aboutmy.email thinks there is a problem

@XL-2000
Copy link

XL-2000 commented May 23, 2024

  1. To be clear; are you using the PHPMailer signing functionality? And if so, can you share that code, just in case?
  2. What does strip_a(...) do? It seems you are pushing a full-blown HTML rendered mail template into a plain-text body-part

Also one thing I notice; you are using:

$this->emailer->Body = $email;
$this->emailer->AltBody = $text;

What happens if you use:

$this->emailer->msgHTML($email);
$this->emailer->AltBody = $text;

@julesbl
Copy link
Author

julesbl commented May 29, 2024

OK, tested this with several email testers and it only errors on one of them so I've reported the bug in their system to them, don't think there is anything wrong with phpMail.
Thanks for the help.
Jules

@julesbl julesbl closed this as completed May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants