I have 3 mail ids say, user1#abc.com, user2#abc.com and user3#abc.com. I have setup PHPMailer with SMTP user as user1#abc.com. Now I set an auto response to user3#abc.com.
When I send a mail from user2#abc.com to user3#abc.com, autoresponse is going to user1#abc.com, the address i used to configure SMTP. How can I make autoresponse to send to FROM address?
$mail->isSMTP();
$mail->Host = 'hostname';
$mail->SMTPAuth = true;
$mail->Username = 'user1#abc.com';
$mail->Password = 'password';
$mail->SMTPSecure = '';
$mail->Port = 25;
$mail->Sender='user1#abc.com';
$mail->AddReplyTo('user2#abc.com', 'User2');
$mail->setFrom('user2#abc.com', 'User2', FALSE);
$mail->addAddress('user3#abc.com', 'User3');
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $mailBody;
$mail->send();
You have not set a to address, so it's falling back to a default.
$mail->addAddress('user3#abc.com');
Many ISPs (for example gmail) will not allow you to set arbitrary from addresses, so if your from address is not working, check that. Also, be sure not to forge from addresses as it will cause delivery failures when you break SPF rules.
If you're writing an autoresponder, check that the inbound message you're responding to does not have a Precedence: bulk header set; autoresponses should not be sent to mailing lists (which should set that header) as it will often cause loops.
Related
I am using PHPMailer library to send SMTP email for booking enquiry. (Note: The same problem I was facing in PHP Pear Mail library as well).
I set the email from as below
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true;
$mail->Username = 'gmail.owner#gmail.com'; // SMTP username
$mail->Port = 465; // TCP port to connect to
$mail->isHTML(true);
$mail->Password = 'xxxx';
$mail->setFrom(mark.antony#example.com, Mark Antony);
$mail->replyTo(mark.antony#example.com, Mark Antony);
$mail->addAddress(gmail.owner#gmail.com, Gmail Owner);
$mail->Subject = $whatever subject;
$mail->Body = $whatever html;
The problem is after sending email in the received mailbox I see the From: is the same as To: (Or same as the gmail/smtp username).
I have fixed the problem on reply to by setting replyTo value.
Is there anyway I can fix this? Or is that how it suppose to be?
Google does not allow you to set arbitrary from addresses, because doing so is usually forgery. If you try to, gmail will ignore it and substitute your Username address, which is what you're seeing.
There is one exception to this: you can set up additional aliases in your gmail settings (which you need to verify), and once you've done that you can use those addresses as from addresses.
If you're using this for a contact form (as it sounds like you are), setting to and from to your own address, and the submitter as a reply-to is the correct way to go, as the PHPMailer contact form example demonstrates.
I am using PHP Mailer library to send mail. Here I set from email address. But that email does not show in the mail.
$mail->SMTPDebug = env("GMAIL_SMTP_DEBUG");
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "mygroup#gmail.com"
$mail->Password = "******";
$mail->SMTPSecure = env("GMAIL_SMTP_SECURE");
$mail->Port = env("GMAIL_SMTP_PORT");
$mail->ContentType = 'text/html; charset=utf-8\r\n';
$mail->WordWrap = 900;
//Recipients
$mail->Sender = "myemail#gmail.com";
$mail->SetFrom("myemail#gmail.com", "My Name",false);
.......
Here I want to receive from address is "myemail#gmail.com". But instead of I am getting "mygroup#gmail.com"
What you're asking for is effectively forgery, and gmail (along with other services) doesn't allow it - it will substitute your account address instead, as you're seeing.
The one thing you can do is set up fixed aliases for your account in your gmail settings, and you can then use those as from addresses, and gmail won't substitute them. Even with this, it still won't let you use arbitrary from addresses on the fly - you have to define them beforehand.
This code is work, email is sent
$mail = new PHPMailer();
$mail->setFrom("name1#gmail.com", "Name");
$mail->addAddress($to); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("name1#yahoo.com", "Reply");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->send())
{
echo 'Mailer Error: ' . $mail->ErrorInfo . "\n";
}
But for some reason, if I change From email to name2#yahoo.com
$mail->setFrom("name2#yahoo.com", "Name");
emails does not sends anymore. Phpmailer does not report any error messages.
name2#yahoo.com is valid working email address related to this web server.
Thanks.
This is covered in the PHPMailer troubleshooting guide.
Most service providers now have strict SPF and DMARC configurations (Yahoo especially, since they invented DMARC) that mean that you cannot send from addresses in their domains except through their own mail servers, or any others included in their SPF records.
Your code is sending through your own local server, which is not a Yahoo server, and thus won't work.
The solution is to send through Yahoo's own servers using authentication for your email account, something like:
$mail->isSMTP();
$mail->Host = 'smtp.mail.yahoo.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->Username = 'me#yahoo.com';
$mail->Password = 'password';
Yahoo's DMARC config won't let you spoof the from address, so you can only use a from address that matches your username - this is probably the cause of the symptom you're seeing.
My webhost does not allow mail accounts to be created. However they have provided me with their SMTP gateway and said no credentials are needed when the mails are being sent from their datacenter.
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = GATEWAY_PROVIDED_BY_HOST
$mail->SMTPAuth = false;
$mail->SMTPSecure = false;
Invalid address: (From): root#localhost
It seems I need to add a from address. But in the case that they do not allow a mail account to be created, what do I put in the from address?
Try to use a valid sender "from" email address.
Update:
You have to use a sender address which is the mail server responsible for (or a white listed one).
normal "#domain.tld" is enought. the name in front of the at is often not tested.
Also possible: you can only send "to" the domain which is the mail server responsible for or you have to authenticate. best is you contact your server provider.
You need to set a From address:
$mail->setFrom('user#example.com', 'My Name');
This will set the from address that appears in message headers, but it will also used as the MAIL FROM command at the SMTP level (where your error is coming from) as it's automatically copied to the Sender PHPMailer property which applies there. That will avoid the fallback to the root#localhost address you're getting.
The other things you're doing to disable authentication are correct.
Create a Google Account and use it:
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Username = "your#gmail.com";
$mail->Password = "*****";
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = "465";
$mail->setFrom('your#gmail.com', 'Your Name');
$mail->addReplyTo('your#gmail.com', 'Your Name');
I'm trying to send a mail with PHPmailer and gmail. But when I send a mail its from my gmail account instead of no-reply. How do I set no-reply as from?
Code I have:
$mail = new PHPMailer();
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "myAccount#web.com";
$mail->Password = "password";
$mail->From = "no-reply#web.com";
$mail->AddAddress($to);
$mail->AddReplyTo("no-reply#web.com","no-reply");
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->WordWrap = 150;
$mail->send();
The mail I get receives (headers):
Return-Path: <myAccount#web.com>
Which should be no-reply#web.com
Thanks in advance
There are two options I would recommend trying:
Log in to the Google Apps mail account for myaccount#web.com, go to Settings, then Accounts, then Send mail as, and ensure that no-reply#web.com has been validated. I haven't tested this, but this should allow to send mail from no-reply#web.com, rather than from no-reply#web.com on behalf of myaccount#web.com.
Actually create a user on Google Apps with the username no-reply#web.com, and send email through that account. If myaccount#web.com needs a copy, you could always BCC the address and setup a filter on no-reply#web.com to forward any failures to myaccount#web.com.
You can't do it. Just imagine sending mail prompting to reply with your bank account credentials from an address validation#yourbank.com.
To have no-reply address you must have an access to the mail server in #your.domain (not gmail) and create such account there, then send emails using this account.