Sending a french email with phpMailer cause strange subject encoding - phpmailer

I'm sending for my system email to users.
For this purpose I used phpMailer.
For english email, no problems.
For french email, subject of the message starts like this:
=?text/html; charset=UTF-8;?Q?Votre_essai_de_14_jours_a_d=C3=A9but=C3=A9?=
Here the potential error code:
$Email_Subject = 'Votre essai de 14 jours a débuté';
$mail->CharSet = "text/html; charset=UTF-8;";
$mail->Encoding = "base64";
$mail->isHTML(true);
$mail->Subject = $Email_Subject;
$mail->Body = $messageHTML;
$mail->AltBody = $messageTEXT;
What can cause this behaviour ?
Thanks.

It wants a character set, but you gave it a MIME content-type declaration, which is wrong. Simply do this:
$mail->CharSet = 'UTF-8';

Related

phpmailer send mails via OWN mailserver, missing DKIM

i'm using phpmailer V 6.6.0
Here at stackoverflow are a lot of hints and tricks, how to create and use key files for sending DKIM-signed mails.
But my problem is very simple.
I can't remember to provide Thunderbird / Livemail / Outlook whatever with a .key-file.
All i want to do is to use phpmailer sending a mail via my mail server. Like all other EMail-Programs do.
This is my code so far:
$Server = "xxxxxx.xxxxxx.com" ;
$Username = "mxxxxx" ;
$Password = "xxxxxxxxxxxx" ;
$mail = new PHPMailer();
$mail->isSendmail();
// Define the sender
$mail->Host = $Server;
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = $Username;
$mail->Password = $Password;
$mail->Hostname = "#thisdomain.com";
$mail->MessageID = "<".time()."#thisdomain.com>";
$mail->XMailer="MyMailer";
//Set who the message is to be sent from
$mail->setFrom($dbset['Sender']);
$mail->addReplyTo($dbset['Sender']);
$mail->addAddress($dbset['Receiver']);
$mail->Subject = "JUST A TEST";
$mail->isHTML(false);
$mail->Body = "This is just a test";
//send the message, check for errors
$Res = $mail->send();
if (!$Res) die('VERY BAD - Error sending mail!');
$mail->__destruct();
unset($mail);
Well it works great, beside of the "DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net;
s=badeba3b8450; t=1652648844;
bh=x8/D1v6jj+heUcnMHbgz3HeVzmgGNIkhaOk...lots of bytes here..."
What am i doing wrong?
I don't need to set up an own mail server.
My mail server at my provider works great, including the DKIM signature.
Why won't it work with phpmailer?
Signing the Email is not the job of the client, it should be done at the mail server.
Or i'm wrong at this?
Helpless
Mac

PHPMailer goes to spam

I have problem with PHPMailer. Messages go to spam on o2 and Hotmail. On other servers it works well. Here is my code:
require_once('class.phpmailer.php');
require_once('class.smtp.php');
$mail = new PHPMailer();
$mail->From = "abc#mydomain.pl";
$mail->FromName = "XYZ";
$mail->AddReplyTo('abc#mydomain.pl', 'XYZ');
$mail->CharSet = 'UTF-8';
$mail->Host = "mail.mydomain.pl";
$mail->Mailer = "smtp";
$mail->SMTPAuth = true;
$mail->Username = "abc#mydomain.pl";
$mail->Password = "password";
$mail->Port = 25;
$mail->Subject = "Subject";
$mail->Body = "Message";
$mail->AddAddress ('xxx#yyy.pl','User');
$mail->Send();
Can anyone help?
Apart from the possibility that your server may be blacklisted for some reason, the most common cause for emails landing in spam servers that i encountered is that the from-address and the server's name do not match.
Consider a from-address like someone#mydomain.com sent from a server cheapwebhosting.com, the recipient mail server sees the discrepancy and will most likely consider this a spam message.
So, you should check the message headers of a test email if something like this is happening here (or if you notice anything else that looks fishy)

from header in PHPMailer

Im using PHPMailer to send emails. Now I have a contact form and when a user fills it out I should receive an email. In the email, when I click reply I'd like to have customer email in there, however im getting my own server email. I also want the email to say 'from: customer#hisemail.com' (customer email).
I believe i have to setup headers here. However I couldn't find any info about PHPMailer headers... Maybe someone could give me an advice? Thanks!
Here is my code:
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->Subject = $subject;
$mail->Sender = $email;
$mail->From = 'myemail#myserver.com';
$mail->FromName = $fullname;
$mail->MsgHTML($question);
$mail->AddAddress($mailmanager, "support");
$mail->AddReplyTo($email, $fullname);
if(!$mail->send()) { echo 'mail not sent'; }
Don't do that. It will fail to deliver on most ISPs because you are trying to forge the from address. Instead, send from your own address and add the customer's address as a reply-to address:
$mail->addReplyTo($customeremail);

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.

PHPmailer class returns true but email is not delivered

I am trying to send an email in following way -
from : xyz#domain1.com
reply-to : xyz#domain1.com
to : abc#domain2.com
cc : abc#domain3.com
My email is getting delivered to the address mentioned in CC (If I replace the emails to and cc, then email is sent to the address mentioned in to)
For some reason, email is not getting delivered to the address abc#domain2.com. If I send the email manually to this address using outlook or gmail, then email is actually delivered. How can I debug this issue ?
I checked spam/junk directories as well, no emails over there. I tried using php mail() function as well as phpmailer class. Both of them return TRUE. What could the reason ? Please help.
$mail->From = "xyz#domain1.com";
$mail->AddReplyTo("xyz#domain1.com");
$mail->AddAddress("abc#domain2.com");
$mail->AddCC("abc#domain3.com");
$mail->Subject = $subject;
$mail->Body = $message;
if(! $mail->Send()) {
echo "Message was not sent";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
Try to set cofigurations beffore send (Gmail config):
$mail = new Mailer();
$mail->SMTPDebug = true;
$mail->SMTPAuth = true;
$mail->CharSet = 'utf-8';
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = '465';
$mail->Username = 'your login here';
$mail->Password = 'your password here';
$mail->Mailer = 'smtp';
$mail->From = 'form mail address';
$mail->FromName = 'from name';
$mail->Sender = 'form mail';
$mail->Priority = 3;
$mail->AddAddress('mail', 'admin name');
$mail->AddReplyTo('replay to', 'admin name');
$mail->Subject = 'subject';
$mail->Body = 'some HTML message here';
$mail->IsHTML(true);
if(!$this->Send()) {
print_r('error: '. $mail->ErrorInfo); // Show errors
}
$mail->ClearAddresses();
$mail->ClearAttachments();
This can also happen if you are sending email from one email address, but authenticating it against a different one (or domain)
Set $mail.setFrom() to the same email for which you are
authenticating against.
check that your server is aloud to send emails the same happened to me in my case i used plesk and for some reason I was not able to send and email until I receive and email I change this configuration and worked check also is you use send mail o qmail if is qmail you have to tell php mailer

Resources