PHPMailer - multiple emails in same Page - gmail

My PHPMailer is working perfectly but my problem is that when i receive the different emails from different personĀ“s , all the emails will be received inside the same message (because PHPMailer send emails always from 1 single email (management#gmail.com)).
Its possible to receive always emails in different messages?? Because like that its confused to manage the email.
IMAGEM_EMAIL
email2
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'management#gmail.com';
$mail->Password = '*********';
$mail->SMTPSecure = 'tls';
$mail->From = $_POST["email"];
$mail->FromName = $_POST["name"];
$mail->addAddress('website#gmail.com');
$mail->AddCC($_POST["email"], $_POST["name"]);
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = $_POST["subject"];

There is two issues here:
1/ Your gmail/inbox is grouping the mails you receive from PHPMailer. And for that, there is no solution. It's what gmail/inbox do and you can't do anything about that.
2/ You want to hit "reply" to these mails and reply not to "management#gmail.com" but to your user's mail. You can add a "Reply-To" field in mails to achieve that:
$mail->addReplyTo($_POST["email"], $_POST["name"]);

Related

phpmailer reply-to not working when reply from mobile app

I'm using phpmailer on my ERP and the from email is a noreply# and the reply-to is my client/company email.
Everything is working, however, I noticed that when a person is replying by a mobile app the reply goes to the "from" email and not the reply-to, also, that happens to the autoresponse.
How can I solve the problem?
This is part of the code
$mail->setFrom($from, $name_from);
$mail->addAddress(getToEmail($iduser));
$mail->ClearReplyTos();
$mail->addReplyTo($reply, "Reply to " . $name_from);
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->Sender = $reply;
$mail->Subject = $subject;
$mail->Body = $message;
one more thing, I was told that mobile clients not always download the entire email but show a button to do so. These clients cannot see "reply-to" if the mail is not fully downloaded.
I am not sure if this is fully true ...

setFrom alternative goDaddy

I understand that gmail, yahoo, hotmail etc. etc. won't work with goDaddy and PHPMailer but what email address should I use for setFrom? I would appreciate any help in figuring this out! (I'm trying to have the name and email entered on an html contact form be emailed to me)
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'Exception.php';
require 'PHPMailer.php';
require 'SMTP.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->SMTPAutoTLS = false;
$mail->Port = 25;
//Set who the message is to be sent from
$mail->setFrom('MY_UNUSABLE_EMAIL', 'MY_NAME');
//Set an alternative reply-to address
$mail->addReplyTo($_POST['email'], $_POST['name']);
//Set who the message is to be sent to
$mail->addAddress('MY_UNUSABLE_EMAIL', 'MY_NAME');
// Content
$mail->Body = <<<EOT
You've recieved a new submission from: {$_POST['name']}.
Their email is: {$_POST['email']}.
EOT;
$mail->Send();
?>

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)

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