Mail does not override from email address in Laravel 5.2? - php

I am sending email using Gmail SMTP account, but I want show different sender email to the receiver. I am using below code to override the from email address.
Mail::send('emails_old.send_message', ['data' => $request->message], function ($message) use ($request, $toEmail, $cc, $bcc, $attacments)
{
$message->to($toEmail);
$message->subject($request->subject);
$message->from('no-reply#xyz', 'No reply');
$message->replyTo(auth()->user()->email, auth()->user()->name);
});
Above code working fine & also overrides sender name, but not email address.
can anybody tells what's wrong I am doing?
Thanks,
Kaleem

Gmail only permits you to use a From address that's in your Settings as a verified alias. You can't (and shouldn't) spoof an email address you don't control. If nothing else, it'll frequently be flagged as spam because of SPF records. – ceejayoz
If you want to use a different email address where the mail is send from try using a mail server, or try using a maildriver such as mailgun.
I only use Gmail SMTP for development, after that I switch over to my mail server.
I'd note that while other services may allow you to do this, it's still a horrible idea. SPF records will send a lot of email sent like this to spam. – ceejayoz
So if it's just for development or a school-project, you can use mailservices like mailgun or Gmail SMTP. Otherwise try to get a mail server to handle no-reply emails.

Related

PHP mail() - Different domain emails for From and reply-to

I want users on my website to use php mail() to send emails from my website domain. I would like users to get replies on their personal email address which will not be my domain email it might be gmail, hotmail or any other. When I do so, the email recipients get a phishing warning in gmail.
How can I set headers in php mail() so different sender and reply-to emails do not make gmail and other services tag the email as spam or phishing.
Your recipients are getting a pishing warning because your emails are not passing SPF checks. That simply means that the from domain you are using is not authorizing your server to send mail on its behalf.
Try using PHPmailer https://github.com/PHPMailer/PHPMailer
You can use it to set a separate from address as well as a specific reply to address
$mail->AddReplyTo('replyto#email.com', 'Reply to name');
$mail->SetFrom('mailbox#email.com', 'Mailbox name');
That being said. The SetFrom address is an address that must pass SPF and preferably DKIM checks to be NOT marked as SPAM or PISHED. This address is recognized as the BOUNCE address where all the bounced emails will be returned to. Not having a valid address may possibly disrupt future deliveries.
The AddReplyTo address will be loaded when the reply button is clicked by the recipient. Keep in mind that even though the message may pass SPF there are many SPAM filters that will potentially mark the message as spam.
The easiest way to get this working is to create an email address on your website (me#mysite.com) then get the website to automatically forward all mail to your gmail account. Then, use the website email address in the 'From' and 'Reply-To' address of your mail() routine.

Php mail function send mail to spam on gmail and aol

I have used default mail() function to send email it sends emails to yahoo successfully but on gmail my emails are going to spam folder due a verification link, if I remove that link then goes to inbox
like is like this
domain.com/abnd.html?code=asdjkahsjkdhkasjghdksghdkjgsakjdg
if remove code then works, with code it goes to spam on gmail.
please help
Could be a number of factors:
Maybe the actual domain name or part of the URL is affecting the overall spam score
Is your email valid HTML and/or and have proper headers
Does the IP address sending mail have a valid PTR record
Are there additional headers being included in the email by the server that you may not want
There are a lot of good resources and helpful things you can use from the AOL Postmaster site including Technical Policy Requirements for Sending Mail to AOL.com, and the feedback loop.
Also see Google Bulk Sender Guidelines for more.

Authenticate Email PHP

I have a web app which needs to send emails to clients 'From' staff email addresses. What's the best way to prevent my messages from being flagged as spam?
For instance, if I own charles#gmail.com, I'd like to be able to send mail "From" that address with PHP in my App, without getting the "This message may not have been sent by...." message.
Right now I'm just using the mail() function within PHP, with Headers for the From, Return Path, and X-Mailer variables.
I'm generally pretty confused by everything I've read so far about SPF and DKIM, so I appreciate any advice. Thanks.
This is a very lengthy subject with lots of things to consider.
The most important rule is to not use HTML and to send only correct mails that people want, and that the recipients do not flag as spam theirselves.
For instance, if I own
charles#gmail.com, I'd like to be able
to send mail "From" that address with
PHP in my App, without getting the
"This message may not have been sent
by...." message.
If you own a gmail address you could just sent the messages via gmail's SMTP service, but keep in mind that gmail has a 500 email sent limit. Below is a topic describing how to use gmail's SMTP server with the popular PHPMailer.
Right now I'm just using the mail()
function within PHP, with Headers for
the From, Return Path, and X-Mailer
variables.
Outsourcing this is probably the way to go using for example:
http://sendgrid.com/
We also offer a Free Plan with 200
Email Credits per day.
To read pricing visit http://sendgrid.com/pricing.html
http://elasticemail.com/
No monthly committments, no minimums,
no limits. Just pay for what you use
at $0.001 / email or less.
http://aws.amazon.com/ses/
Email messages are charged at $0.10
per thousand.
http://aws.amazon.com/ses/pricing/
http://www.cloudsmtp.com/
http://postmarkapp.com/
Just to name a few which are very cheap to use without any hassle/setup.
If instead of using the mail() function, you use an SMTP mailer such as the PEAR mailer package then you can send the mail using google's own SMTP servers. This will require you to provide the correct credentials to the google account you wish to send from. This should avoid the issue you are having.
One of the first things you need to ensure is that the email "From:..." really is from your server e.g your_mailings#yourcompany.com and it must exist and be a valid email on the server where the script works. You should try setting the sendmail user at the top of your script (assumes Linux server):
ini_set('sendmail_from', 'your_email#your_server.com');
Then you add a "Reply-To:" header and use your staff addresses perhaps and recipients will at least seem to have got an email that can be replied to. Without that you probably won't even get as far as being spam, you will get blocked on the way there.
This thread shows some of that and note the comments on PHPMailer - it is a good way to handle mailing and I have found it more successful than simple mail();
PHP mail form isn't working

Can I use SMTP with Swift Mailer while not defining a username and password

I am trying to use Swift Mailer to send an email to a client on her website. The problem is, I do not know her username/password email information, and I do not want to use mine.
Is there a way to use SMTP with Swift Mailer, and not define a username, password, or email host? Kinda how the mail function will allow you to use anything for the to/from addresses.
This is what I have for one of our scripts and I believe it does exactly that.
$message = Swift_Message::newInstance()
//Give the message a subject
->setSubject('Webinar Registration')
//Set the From address with an associative array
->setFrom(array('FROM EMAIL ADDRESS' => 'FROM NAME'))
//Set the To addresses with an associative array
->setTo(array('TO EMAIL ADDRESS'))
//Give it a body
->setBody('My Message')
//And optionally an alternative body
//->addPart('<q>Here is the message itself</q>', 'text/html')
;
//Create the Transport
$transport = Swift_SmtpTransport::newInstance('127.0.0.1', 25);
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Send the message
$result = $mailer->send($message);
This was probably copy-pasted and slightly modified from the Swift mailer documentation. All we're doing is connecting to SMTP on localhost.
Edit: Looking at comments on the original post, I do have to wonder about triggering spam filters. We haven't really had a problem with it... one, maybe two users have complained about not receiving e-mails. If there's any good documentation on this kind of stuff and ways to avoid these problems, I'd love to have a link to it. I think we just have the default IIS SMTP server running on our machine as set up by our provider.
Another Edit: Ah, if this is going on to someone else's website, we don't know exactly how they're set up. I wonder if you could create an account with some other e-mail provider (assuming it's not against their terms of use.) Maybe I jumped the gun with my post, sorry.
In order to do this right you have to use a real email address and send it from a server that is properly configured. Otherwise your mail will end up in their spam box.
Just have your client set up an email address called support#whateverthedomainis.com which would be for this. If for whatever silly reason they can't do that then set up a mail address at gmail or some other free email provider and send it through their mail server.
There is a LOT that goes into properly configuring a mail server in todays world. From blacklist management, reverse dns configuration, SPF setup, etc. Point is providers are getting more finicky every day and if you want to see your application work long term then you'll need to do this right.
Hope that helps.

How to hide sender email address using phpmailer?

I am using phpmailer to send email. I need to know how to hide or mask sender email address
You can specify any sender email address anyway, since SMTP by itself does not place any requirements on sender email addresses.
If the actual SMTP server you use places restrictions on email addresses (e.g. corporate servers which do not allow sender emails outside of the company domain) there's no way around that, unless of course you can influence the mail server configuration.
Update:
You say in a comment that you want to use gmail to send email where the sender's address is not a gmail address. There is no way to do that.
This is a rare situation you have here... if you do not have a mail server you can still tell PHPMailer to send from a different address just set the From attribute of the PHPMailer object to the address you want. But Wait! if your server doesn't exists, the client can't verify the account and then your mail will more likely be deleted (moved to spam in the more benevolent scenario). If you are trying to mimic third party mail, I'll help you no futher.
Note: Your mail server may be valid but clients are still unable to verify it, and thus you are getting mails delivered to spam or deleted. Check "Must Read" to below to have some inside on how to solve this.
On the other hand, if you already have a mail server, then tell PHPMailer you want to use it, set the Host and Port attributes to your domain name and port respectively. The same if you want to use an account form a different server, remember to set the attributes Username and Password correctly, you may also need to set SMTPAuth = true; and SMTPSecure = 'ssl'; depending on the server. [Note: Username and From may differ]
Now, if you want to use an account from Gmail, you could easily set an alias in Gmail to send as another account [Go to Settings-> Accounts And Import -> Send mail as -> (click) Send Mail From Another Address], that can be the case if you have a mail server but you cannot afford to have it online, you will need to start your server so you can receive the confirmation code Gmail generates to verify your account. Check recommended read for PHP side configuration details.
Lastly if for some rare circunstancies you can't tell PHPMailer to use your mail server, but you do in fact have one, and that one is able to recieve the mail... you can use AddReplyTo('me#example.com', 'My Name'); Most clients will understand that any reply to the message must be (unless explicitly defined by the user) directed to "me#example.com" in this case.
Disclaimer: I take no responsibility of any harm result of the use of the method I mention here, such as (but not limited to) your mail account getting banned.
Must read:
Coding Horror on sending mail via code
Recommended read: PHPMailer Tutorial (old version)
No need (neither a good way) to hide or mask whatsoever.
I assume you already know how to use the class you are talking about.
You probably have some variable for sending email, like
var $From = "someguy#whatever.com";
you can type whatever you want into that email address. Gmail dont care what email things is sent from.
And no, this dosent sound very legit.
One more thing: Gmail requires a gmail account to relay mails. Its no problem, it wont be visible.
You want to "show the company email address as sender" but you "didn't (sic) have any email server"?
Can anyone actually send you email at your company email address? If so, use that server which is hosting your email to send out from.
If you don't really have a company email address, then I suggest you get a gmail address like companyname#gmail.com and just send from that. Otherwise the email will appear as spam to a great many of your recipients.
Now, if the people you are about to send an email to actually signed up to be on your mailing list then you can use a third party application like Constant Contact to do your broadcasts from.
If they haven't, then I suggest you not send an email at all.
in mail headers you can have both a Sender: and a From: header which in most mail clients is displayed as either just the From or in some cases Sender on behalf of From, using this way is a nice and clean way to be able to send From a different mail address then the actual Sender mail server
This is highly illegal.
var $From = "someguy#whatever.com";
Is the only option your have for trying to hide email address. But no matter what your email will be inscribed with IP. Someone who knows what they are doing will still be able to trace the email back to the source.

Categories