I asked a similar question earlier, but the context has changed a bit. I want to use swiftmailer to send an email in Symfony 2. The problem is I'm using the gmail SMTP server, and so when my message arrives, my email client shows it from gmail.com, rather than mydomain.com. How can I fix this?
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom(array('digest#mydomain.com' => "Digest"))
->setSender(array('digest#mydomain.com' => "Digest"))
->setCharset('iso-8859-1')
->setContentType('text/html')
->setTo('myemail#gmail.com')
->setBody($this->renderView('email.html.twig', array()));
$this->get('mailer')->send($message);
The Gmail SMTP server only allows you to send mail using the email address you're aithenticating with. So if you configured Symfony with
mailer_transport: gmail
mailer_user: myemail#gmail.com
mailer_password: ******
All your messages we'll look like they're from myemail#gmail.com
What you can do maybe is use another smtp server that is more flexible in the types of From addresses they will allow. If you are on a local development server, you could use your ISP's SMTP server, or use one of the various email as a service provider, such as Sendgrid, Mailjet or postmarkapp
They all allow you to send messages from any address you can prove ownership of, after some configuration steps.
One thing that may be worth trying also if you really want to use the gmail smtp server, is to define your from address in your "Send mail as" Gmail configuration (in Settings -> Accounts). This will let your app send email using the configured adresses in the From: field.
Related
I have a VPS hosting and I am using SwiftMailer to send emails using an smtp from another hosting.
When I send an email to the user the source mail contains my VPS ip address and domain in headers, like the following below:
Received: from [ip.ip.ip.ip] (port=•port• helo=mydomain.name) by ....
I was able to hide the domain from swiftmailer using setLocalDomain, but wasn't able to change the IP address even when using setSourceIp on SwiftMailer.
Hint: I don't have access to smtp hosting, I have just my VPS and smtp credentials.
I'm configuring Moodle for a school project and there is a problem in email confirmation process.
following are my configurations:
outgoing mail confirmations
SMTP hosts: stmp.gmail.com:465
STMP security:TLS
STMP Auth Type:LOGIN
SMTP username:****#gmail.com [*admin e-mail*]
SMTP password:****
SMTP session limit:1
no-reply domain
no-reply address:***#gmail.com [*admin e-mail*]
Allowed email domains :
Email display settings
Character set : UTF-8
Allow user to select character set :no
Allow attachments: yes
Email via information: always
when user signed up; admin gets a notification that new user required access but the new user wont get any confirmation email.[before and after confirmation from site admin]
no email can be found in spam or inbox.
please help!!!
For the outgoing mail configuration you should just leave all the settings blank or revert them to their defaults. Unless you have a dedicated SMTP server (i.e. one that is hosted within your organisation and is specifically configured to relay outgoing mail from your Moodle server) then you should just let Moodle use PHP's own mail libraries to send mail.
Hope this helps.
I will be using G Suite (formally Google Apps) to host the email of a site that runs off a separate host.
However, there is a contact form on the website, I haven't looked at it yet, but I assume it will use the standard mail() function.
As I understand it mail() will still use the servers mail server to send the mail, it may be a dumb question, but I assume this won't cause any spam detection issues because of this? Like, I know some servers won't accept mail if the From and/or Sender headers don't match the server it is coming from (or in some cases if the email you set in these headers doesn't exist).
So, if the mail is hosted on G Suite, and the email address that is setup in the From/Sender headers exists on G Suite this won't cause any issues correct?
Lastly, I know it's probably a better idea to use SMTP to send the mail via Google, but I may not have that choice, so I wanted to find out the answer to the above just in-case.
Edit: As per Nima's answer, is this something that can be avoided, or only with using Googles SMTP server to send with?
If you want it simple, then simple use SMTP.
Because of spam, multiple mail server provider are blocking mails from mail servers that have no correct RDNS (Reverse DNS) and MTA name configured.
You want to make sure that all three names are matching according to your MX Record:
Sender Hostname (e.g *mail#demohost.com, note that from can be what ever you want)
MTA-Name/HELO-Hostname (Configured in Mailserver, e.g demohost.com)
RDNS (Basicly it gives per IP-Adress the Hostname (e.g 42.42.42.42 -> demohost.com)
Also make sure your php.ini has the correct configuration for your Mail Server. Congrats you can now send Mails using mail(...).
As I said, it's probably most simple by just using SMTP. Assign the hard work to a hoster.
When you use GSUITE for hosting emails, it's obvious that you will be providing some domain name to GSUITE.
Now emails are marked spam and not spam based on the content as well as certificates of sending server and sending servers have different services for Transactional and Marketing Oriented emails. And GSUITE only provide transactional mail service, and transactional mails from a mail service --having valid certificates and not black listed-- lands directly into Inbox or Other Label, but Spam/Promotion.
Now GSUITE is having all correct certificates and I don't think there is any consumer oriented mail service provider, which blocks emails coming from google servers.
Other Question:-
Does the From Address in E-MAIL headers matters?
Upto now I have never seen from address impacting anything on receiving servers, but some consumer mail services block the usage of from address other than the account email address, just like mobile operators don't let us use someone else's caller id(Ideally).
But mail service providers to businesses let you use any address as from value in e-mail headers.
Edit:-
If you are still unsure about delivery of emails, you can use replyTo header with out any problem.
PS:- I have tested this myself with thousands of emails but using SendGrid servers.
http://php.net/manual/en/function.mail.php
The Windows implementation of mail() differs in many ways from the
Unix implementation. First, it doesn't use a local binary for
composing messages but only operates on direct sockets which means a
MTA is needed listening on a network socket (which can either on the
localhost or a remote machine).
On linux the sendmail executable is used to talk to the SMTP server configured on windows you can / could configure mail() function to use SMTP
So the best way is to use SMTP directly to send the email to Gmail to send the email.
Taken from:
https://stackoverflow.com/a/33506709/623150
Here is a way to do it with PHP PEAR
// Pear Mail Library
require_once "Mail.php";
$from = '<your#mail.com>'; //change this to your email address
$to = '<someone#mail.com>'; // change to address
$subject = 'Insert subject here'; // subject of mail
$body = "Hello world! this is the content of the email"; //content of mail
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'your#gmail.com', //your gmail account
'password' => 'snip' // your password
));
// Send the mail
$mail = $smtp->send($to, $headers, $body);
If you use gmail smtp remember to enable SMTP in you gmail account,
under settings
On a Linux Server you can't use SMTP via the mail function.
Okay, I'm at my whit's end here. I have a client whose site is hosted on GoDaddy and that uses Outlook. I've written a PHP script to send mail to one of their domain e-mail addresses from a contact form on their website.
I can get this e-mail to send to every single service except outlook/exchange/live/microsoft accounts.
I read that using PHPMailer was a good idea, so this is what I'm currently using to send mail:
//$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "a2plcpnl0287.prod.iad2.secureserver.net";
$mail->Port = 465;
$mail->Username = "test#alamohomefinance.com";
$mail->Password = "xxxxxxx";
$mail->SetFrom('yourname#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (hotmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$address = "jakerevans2#live.com";
if(!$mail->Send()) {
error_log("Error from calculator!". $mail->ErrorInfo);
} else {
error_log("Success from calculator!");
}
This e-mail gets sent to my gmail account and some others, but not to my .live account or my client's Outlook address.
I've tried everything I've found on the internet so far, nothing is working. Any ideas or thoughts anyone?
Thanks!
EDIT:
The Godaddy server has an SPF record that reads: v=spf1 include:spf.protection.outlook.com -all
I've created a DKIM key from https://www.port25.com/dkim-wizard/ and added a DKIM TXT record to GoDaddy, with the following details:
Host: key1._domainkey.alamohomefinance.com
TXT Value: k=rsa\; p=MIIBIjA...
I've added a DKIM record, with the following details:
Name: _dmarc.alamohomefinance.com
TXT Value: v=DMARC1; p=quarantine; sp=none; ruf=mailto:user#example.com; rf=afrf; pct=100; ri=86400
Am testing now to see if these changes make a difference...
First up, you should look at the PHPMailer troubleshooting guide, which has a little section on GoDaddy, and many other problems.
You will get much better feedback on what's going on if you enable debug output of server messages, so set SMTPDebug = 2, and see what it says.
GoDaddy is known to block outbound SMTP, and generally will either simply fail to connect (see many questions on SO about that), or cause TLS verification failures as you get redirected transparently to their mail servers.
In your code you've got the smtp.live.com Host, but this username:
$mail->Username = "a2plcpnl0287.prod.iad2.secureserver.net"
secureserver.net is the domain used for GoDaddy's mail servers, and that user name is the name of an actual GoDaddy mail server, so it seems very unlikely that you should be using it as a user id for live.com, especially since GoDaddy will be rotating mail servers frequently, so you're unlikely to get the same one every time - is that really your login ID for live.com?
I'm also suspicious of the phrasing of your question: you do not need to connect to live.com to send email to live.com - there's nothing stopping you sending to a live.com address from a connection through gmail, so it sounds like you may have a conceptual issue. The Host, Username and Password properties are for the mail server that you send out through, not that you are sending mail to.
As I said, normally GoDaddy doesn't allow remote SMTP at all, so I'm very surprised if you've had it working without using a GoDaddy mail server, so I suspect you've had something else work, not what you think.
I can also see you've based your code on an obsolete example, so make sure you're running the latest PHPMailer.
Update:
I noticed something critical. The code does not call $mail->isSMTP();. This means that it's not using SMTP at all, it's using the default mail() function, and as such none of the SMTP config makes any difference at all. The message will be submitted to your local mail server, which will then relay through GoDaddy's server. Look in your mail server's log file to see what's happening, usually in /var/log/mail.log or similar.
Check your server ip on http://mxtoolbox.com/blacklists.aspx . I've noticed Microsoft is very picky about blacklisting. I've had this issue with a brand new I.P addresses that were acquired with an apparent bad rep. If your on godaddy on a shared account ip it's very likely either the ip or entire subnets are blocked by default.
I know about the mail function in php:
mail ($to, $subject, $msg_body,$headers);
But since I cannot access my host's php.ini file, I've been provided with the following details:
SMTP host: mailout.host.com
Port: 25 SMTP
Username: email#domainname.com
SMTP Password: not required
Authentication: Disabled
Encryption: Disabled
How can I use these details to send out emails?
EDIT: I used example pointed by Blender (below) and it seems to work fine for all emails except gmail. Any idea why? Is it to do with Fully Qualified Address?
PHPMailer is a very well known and widely used alternative
Check out the SMTP mail example
You can use SwiftMailer (http://swiftmailer.org/) to send out emails through any email account you can login to, including gmail. It's very robust, but does have a bug where it uses a lot of memory for emails that have a lot of html in them.