5

I am trying to create a test site that handles paypal payment. I am trying to send users an email using PHP SwiftMailer after a successful payment (which is my IPN).

Here is my code for the transport:

        $transport = Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465, 'ssl')
          ->setUsername('xxx@xxx.co.uk')
          ->setPassword('xxxx');    

    $mailer = Swift_Mailer::newInstance($transport);

I have tried to use googlemail and another email which is hosted under a shared server and both have problems giving out an error.

Unfortunately, I am getting this usual error:

  Fatal error: Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "xxx@xxx.co.uk" using 2 possible authenticators' in /home/xxx/public_html/paypal/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:184 

  Stack trace: 

  #0 /home/xxx/public_html/paypal/lib/classes/Swift/Transport/EsmtpTransport.php(312): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport)) 

  #1 /home/xxx/public_html/paypal/lib/classes/Swift/Transport/AbstractSmtpTransport.php(120): Swift_Transport_EsmtpTransport->_doHeloCommand() 

  #2 /home/xxx/public_html/paypal/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start() 

  #3 /home/xxx/public_html/paypal/ipn.php(113): Swift_Mailer->send(Object(Swift_Message)) 

  #4 /home/mctikudo/public_html/paypal/ipn.php(46): sendMail(Resource id #3, Array) 

  #5 {main} thrown in /home/xxx/public_html/paypal/lib/classes/Swift/Transport/Esmtp/AuthHandler.php on line 184

I have done some research and tried several approach in the setting of my transport. But still nothing seems to work. Until I just tried to place my IPN code to another server under another hosting company and surprisingly, it works. Same code from the other one.

This is why I guess there is something in the other server must be set or something.

Are there things that I need to make sure that is enabled on my server to have the SwiftMailer work?

Atasha
  • 489
  • 1
  • 9
  • 28
  • Some domains don't let sending mails on other domains, one can only send emails to "xyz@yourdomainname.com". Check if that's not the case here. For example awardspace.net. – Amit Singh Oct 02 '13 at 11:17
  • 3
    I made it work by applying the answer here: http://stackoverflow.com/a/7170687/882773 – Atasha Oct 02 '13 at 12:31
  • 1
    I made this work with by following the suggestion here: http://stackoverflow.com/questions/7170607/hostgator-wont-send-mail-via-php-swiftmail-api/7170687#7170687 – Atasha Mar 21 '14 at 12:45
  • Please refer my answer given under different post. http://stackoverflow.com/a/26429962/3857499 – user3857499 Oct 17 '14 at 17:05

4 Answers4

18

This might be old but somebody might get help through this. I too faced the same problem and received a mail on my gmail account stating that someone is trying to hack your account through an email client or a different site. THen I searched and found that doing below would resolve this issue.

Go to https://accounts.google.com/UnlockCaptcha‎ and unlock your account for access through other media/sites.

UPDATE : 2015

Also, you can try this, Go to https://myaccount.google.com/security#connectedapps At the bottom, towards right there is an option "Allow less secure apps". If it is "OFF", turn it on by sliding the button.

roneo
  • 1,179
  • 13
  • 22
5

As already stated this might be old but you can try and allow gmail to send mails through less secure apps.

https://www.google.com/settings/security/lesssecureapps

This made it work for me and I had the same issue.

PvPlatten
  • 530
  • 6
  • 14
3

I know this is old but hopefully this points someone in the right direction. I had this same problem when using a Mandrill and Swiftmailer combination.

My issue was that the server was stopping SMTP messages from port 587, and this was in relation to the FKA SMTP Tweak settings which were on my server.

So if you have Cpanel and can access WHM, try looking at your mail settings under tweaks to see if outgoing SMTP mail is restricted. Other option is that maybe your server considers a port as suspicious. Try changing the port, I found that my hosting company had a list of suitable ports.

adamalexanderw
  • 1,143
  • 2
  • 15
  • 28
  • 2
    Took me an entire day to figure this out. When this feature (FKA SMTP Tweak) is enabled will redirect outgoing SMTP connections to the local mail server. root, exim, and mailman are still allowed to make direct connections. – Steven Teo Jul 04 '15 at 16:24
  • Changed this, but hasn't helped yet. – PlanetUnknown Aug 26 '15 at 01:27
0

i know im too late but i was frustrated with this error and i fixed it thanks to all these answers, i hope this helps.

This worked with a website that is hosted on AWS Elastic BeansTalk. add this in your email.php or whatever

require_once 'files-needed/vendor/autoload.php';
//to send emails to our users
//google does not recognize this so we must change google settings
//(Allow less secure apps) Turned on
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.gmail.com', 587, 'tls'))
    ->setUsername(EMAIL)
    ->setPassword(PASSWORD);

// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);

And thanks to roneo i did this

Go to https://accounts.google.com/UnlockCaptcha‎ and unlock your account for access through other media/sites.

Step 1:(important!!) Just make sure that when you access this link

https://accounts.google.com/UnlockCaptcha‎

you are signed in from the same email from the php code, because i thought i was but when i entered https://accounts.google.com/ turns out it was another email.

Step 2: i followed the instructions in the page, then immediately went to my website and sent an email, and Finally.. it WORKED!!

iiWOLF77
  • 13
  • 3