简体   繁体   中英

phpmailer sends email out with the subject line added twice

There is a weird error in a very basic implementation of phpmailer in which the subject line adds itself twice, its only been added once in the code:

$mailer->Subject = "My Subject";
$mailer->Send();

The output is that it gets the mail but with the Subject Line seen twice in the email client. Its very odd, and its not been set earlier on in the code.

Anyone seen this error and found a fix for it ?

I solved the problem. There is a property called SingleTo, it needs to be set to true. http://phpmailer.worxware.com/index.php?pg=properties

$mail->SingleTo = true;

and it should work fine.

I know this is old, but I found a solution:

phpmailer adds the $subject and recipients into the $headers in the create_header function but when you use the default send method - php mail - it adds them again. mail($to, $this->Subject, $body, $header)

To fix this just comment out these lines in the create_header function of phpmailer.

//$header[] = $this->addr_append("To", $this->to);

//$header[] = sprintf("Subject: %s\n", trim($this->Subject));

Have you tried viewing the email in multiple clients? It seems that perhaps either your subject is being included in the header, or that your email client may well be showing it twice for some reason. Perhaps as a header for the email?

Personally I've never seen or heard of a bug of this nature.

PHPMailer's ->$Subject property is just a variable. Assigning a new value will not append it to the previous one, it'll overwrite and replace any previous subject. Unless you're using something like:

$mail->Subject .= 'extra subject bits';
or
$mail->Subject = $mail->Subject . 'extra subject bits';

then you'll have to look elsewhere to find the cause. Perhaps there's a bug in your mail server's configuration, or you've subclassed PHPMailer and your super-class is doing something funky.

You can check if it's the receiving server's problem by sending the same email to multiple accounts handled by different servers. ->AddBCC, ->AddCC, and ->AddAddress multiple times will take care of that. Just make sure the addresses are handled by different servers.

PHPMailer 6.0.3 has a similar issue.

Emails were being sent with duplicate header entries for "Subject", causing emails to bounce from @yahoo, @sky.com and @rocketmail.com recipients. Despite this, emails were being accepted by Hotmail and GMail.

In /PHPMailer6/PHPMailer.php, commenting out lines 2299 - 2301 fixed the problem.

/*if ('mail' != $this->Mailer) {
    $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
}*/

Elsewhere my use of PHPMailer to send mail, is typical of the code samples

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM