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);
Related
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 ...
Using PHPMAILER class to send email from my website to my gmail account, if I try to response this consult gmail puts this gmail account as destination address.
This issue happens only with gmail, yahoo for example works fine.
The code I'm using to send from the form:
$mail = new PHPMailer();
$mail->IsSendmail();
$body = "body of consult";
$mail->CharSet = 'UTF-8';
$mail->From = "user#hotmail.com"; // sender
$mail->FromName = "User Name"; // sender
$mail->addReplyTo("user#hotmail.com","User Name"); // sender
$mail->AddAddress("myaccount#gmail.com", "my name"); //destination (Me)
$mail->Subject = "User Subject";
$mail->AltBody = ""; // optional, comment out and test
$mail->MsgHTML($body);
$mail->IsHTML(true);
if(!$mail->Send()) {
return(false);
} else {
return(true);
}
Is there any value o function to add to phpmailer class?
I appreciate any help.
Thank's
This is a gmail limitation. It does not let you send from arbitrary "from" addresses, only your account address. You can add additional aliases in your gmail preferences, but you can't use a non-gmail address.
This is covered in the PHPMailer documentation.
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.
I have come across some weird behaviour in PHPMailer. I am using my gmail account for the SMTP settings. But every time PHP sends an e-mail(in this case, it's for resetting a password), I receive the same e-mail too. Except for when the password reset is requested for my gmail account.
Here is the code;
//set email settings
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'ssl://smtp.gmail.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Port = 465;
$mail->Username = 'mymail#gmail.com'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->From = 'noreply#bla.com';
$mail->FromName = 'Bla';
$mail->AddAddress($email); // Name is optional
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Bla registration';
$mail->Body ="
<html>
<header><title>Welcome to Bla</title></header>
<body>
<p>Hello,</p>
<p>Welcome to Bla. Thank you for registering an account. Before you can start inventing music, please activate your account</p>
<p><a href='http://www.bla.com/register/activate.php?activation=$activationcode&email=$email'> http://www.Bla.com/register/activate.php?activation=$activationcode&email=$email</a></p>
See you soon on Bla!
</body>
</html>";
$mail->Send();
There is no error or something like that. The e-mail is actually send, and received. Only problem is that I receive as well because the e-mail address in Username is my e-mail address. Does anyone know why this happens?
Add ClearAddresses like this->
$mail->Send();
$mail->ClearAddresses();
And solved.
Greetens
Try to change
$mailer->isSMTP();
to
$mailer->Mailer = 'smtp';
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