Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namecheap Hosting: Mailer Error: SMTP connect() failed. #1115

Closed
csandreas1 opened this issue Aug 1, 2017 · 37 comments
Closed

Namecheap Hosting: Mailer Error: SMTP connect() failed. #1115

csandreas1 opened this issue Aug 1, 2017 · 37 comments

Comments

@csandreas1
Copy link

csandreas1 commented Aug 1, 2017

My script is tested and working on heroku. After transfering my website to namecheap i get SMTP connect() failed error. I have contacted their weak support and the only thing they are saying is check your script etc. They claimed that they opened ports 587 tls. Is there anything i can tell them to do to fix the problem? Because it is totally a server issue

@Synchro
Copy link
Member

Synchro commented Aug 1, 2017

It's unlikely to be a server issue, far more likely to be a network issue. If you follow the troubleshooting guide, it will allow you to diagnose where the problem is.

@Synchro Synchro closed this as completed Aug 1, 2017
@csandreas1
Copy link
Author

csandreas1 commented Aug 1, 2017

i have enabled smtdebug= 2 and i get this message

https://accounts.google.com/signin/continue?sarp=1&amp;scc=1&amp;plt=AKgnsbsL534-5.7.14 K_XXe3SWe2qjPJYq-kU5AaU-jnFYMuusqAfob5XogbUT79zz30h9m5tSBZZX8e-C1im0ua534-5.7.14 Pnt8duPHjHcH6GCvGS4QfMnHemJrFb2X8zcZEVxRBzkugNfaTxzaVW0sXVQU9YefRqlPmG534-5.7.14 IHfVVqnHqX7IJL6h0mQw2JBRfmUepEO-okVPkjSqLUt2NUEvB0_kMcVrxV9a1dDX-5Oeuf534-5.7.14 hwzcgLor80gVTn8mZyfCyVUnx2LYE&gt; Please log in via your web browser and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 v44sm40952005wrb.53 - gsmtp<br> 2017-08-01 19:22:01 SMTP ERROR: Password command failed: 534-5.7.14 &lt;https://accounts.google.com/signin/continue?sarp=1&amp;scc=1&amp;plt=AKgnsbsL534-5.7.14 K_XXe3SWe2qjPJYq-kU5AaU-jnFYMuusqAfob5XogbUT79zz30h9m5tSBZZX8e-C1im0ua534-5.7.14 Pnt8duPHjHcH6GCvGS4QfMnHemJrFb2X8zcZEVxRBzkugNfaTxzaVW0sXVQU9YefRqlPmG534-5.7.14 IHfVVqnHqX7IJL6h0mQw2JBRfmUepEO-okVPkjSqLUt2NUEvB0_kMcVrxV9a1dDX-5Oeuf534-5.7.14 hwzcgLor80gVTn8mZyfCyVUnx2LYE&gt; Please log in via your web browser and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 v44sm40952005wrb.53 - gsmtp<br> SMTP Error: Could not authenticate.<br> 2017-08-01 19:22:01 CLIENT -&gt; SERVER: QUIT<br> 2017-08-01 19:22:01 SERVER -&gt; CLIENT: 221 2.0.0 closing connection v44sm40952005wrb.53 - gsmtp<br> SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting<br> Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

@Synchro
Copy link
Member

Synchro commented Aug 1, 2017

Did you try doing what it said?

Please log in via your web browser and then try again. Learn more at https://support.google.com/mail/answer/78754

@csandreas1
Copy link
Author

csandreas1 commented Aug 1, 2017

yes i did. By the way i just changed host today.

@csandreas1
Copy link
Author

csandreas1 commented Aug 1, 2017

I will see what i can do if i won't find a solution until tomorrow i will swap to php Mail()

@Synchro
Copy link
Member

Synchro commented Aug 1, 2017

This is a common problem that has nothing to do with the code; it's just gmail's policy, and this question has come up here and on Stack Overflow many times: when gmail sees you use a new authentication mechanism, it wants to be sure it's you.

PHPMailer can act as a wrapper around mail() (in fact it does so by default). Calling mail() yourself is generally a very bad idea.

@csandreas1
Copy link
Author

Php mail sends emails directly from a script which opens and closes an SMTP socket.

@Synchro
Copy link
Member

Synchro commented Aug 1, 2017

No it doesn't. It passes a message via a shell to a sendmail binary. That binary usually opens a synchronous SMTP connection to localhost, but that is entirely invisible to PHP. Sending via mail() is slower, less secure, and provides less feedback and control than sending via SMTP to localhost directly from PHPMailer. Either way, PHPMailer can act as the front-end, dealing with message construction and encoding, which mail() doesn't provide any help with at all.

@csandreas1
Copy link
Author

okay nice to know it, i know smtp is much faster and better but i have to figure how to solve this problem

@csandreas1
Copy link
Author

Is that possible to try using microsoft smtp settings? I'm having trouble to find those settings

@csandreas1
Copy link
Author

csandreas1 commented Aug 2, 2017

okay here they are:

Server name: smtp-mail.outlook.com
Port: 587
Encryption method: STARTTLS

@csandreas1
Copy link
Author

Now i get different error:

2017-08-02 07:33:28 SMTP ERROR: DATA END command failed: 550 5.3.4 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:69000000, 17.43559:0000000060010000000000000000000000000000, 20.521

SMTP Error: data not accepted.

Mailer Error: SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:69000000, 17.43559:0000000060010000000000000000000000000000, 20.521
SMTP code: 550 Additional SMTP info: 5.3.42017-08-02 07:33:28 CLIENT -> SERVER: QUIT

2017-08-02 07:33:28 SERVER -> CLIENT:

2017-08-02 07:33:28 SMTP ERROR: QUIT command failed:

@Synchro
Copy link
Member

Synchro commented Aug 2, 2017

The name SendAsDeniedException suggests that it doesn't like you sending as whatever from address you're using. Is it different from your Username?

@csandreas1
Copy link
Author

yes

@csandreas1
Copy link
Author

emails are receiving in localhost and heroku but not in namecheap hosting. I have contacted again their support but they can't find a solution.

@Synchro
Copy link
Member

Synchro commented Aug 2, 2017

You're using a from address that's different from your username, and that's what it's complaining about – so don't do that?

@csandreas1
Copy link
Author

here is the script: https://www.mpoliasma.top/blog/blog.php try it your self. I told you script works fine nothing error in the code.

@csandreas1
Copy link
Author

i get this now: {"error":"You must provide at least one recipient email address."}

@Synchro
Copy link
Member

Synchro commented Aug 2, 2017

Are you calling addAddress()? Is it successful?

@csandreas1
Copy link
Author

$mail->AddAddress($to);

@Synchro
Copy link
Member

Synchro commented Aug 2, 2017

So you're not checking the return value like I asked?

@csandreas1
Copy link
Author

the return value is my email. What do you mean ?

@csandreas1
Copy link
Author

csandreas1 commented Aug 2, 2017

anyway they said they opened a Ticket DKY-580-73644 and they will try to solve this issue

@Synchro
Copy link
Member

Synchro commented Aug 2, 2017

addAddress is a function; check what it returns, don't just assume it works:

if (!$mail->addAddress($to)) {
    echo htmlspecialchars($to), ' is not a valid address';
}

@csandreas1
Copy link
Author

csandreas1 commented Aug 2, 2017

this is what it returns:

Mailer Error: SMTP connect() failed. https:<a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="5c73733b352834293e723f3331730c140c113d3530392e730c140c113d3530392e732b35373573082e33293e30392f3433332835323b2b393e38333135323d2e6d1c">[email&#160;protected]</a><script data-cfhash='f9e31' type="text/javascript">/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */</script>gmail.com is not a valid address

@Synchro
Copy link
Member

Synchro commented Aug 2, 2017

What?! Clearly whatever you're putting in $to is not an email address! This is all very basic PHP debugging, I can't hold your hand for every trivial problem like this, show some initiative!

@csandreas1
Copy link
Author

sorry i am not experienced in programming , i am still a student

@csandreas1
Copy link
Author

csandreas1 commented Aug 2, 2017

Here is my complete script:

sendemail.zip

@csandreas1
Copy link
Author

In localhost where i receive the email it returns :

[email protected] is not a valid address

@Synchro
Copy link
Member

Synchro commented Aug 2, 2017

You're passing in the user-submitted address:

$mymail=smtpmailer("[email protected]",$_POST['Email'], $_POST['Name'], $_POST['message']);

Then using it as the From address:

$mail->SetFrom($from, $from_name);

That's straightforward forgery/spoofing, and gmail will not allow it, and it will cause SPF failures even if it did. Base your code on the gmail example provided with PHPMailer, and read the comments in the code.

@csandreas1
Copy link
Author

csandreas1 commented Aug 2, 2017

But why they allow it through heroku and localhost with the same code. That's weird. I will try to change my code to see if emails will be sent.

Based on this code: https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps

@csandreas1
Copy link
Author

I have added exactly the same script as this link but it doesn't seem to send emails. They send from localhost though.

@csandreas1
Copy link
Author

i'm not an expert otherwise i would fix the problem the same day

@csandreas1
Copy link
Author

OKay i fixed the problem. The trick was this link:

https://accounts.google.com/b/0/DisplayUnlockCaptcha

@arslbbt
Copy link

arslbbt commented Oct 5, 2017

@csandreas1 last link is for asking to app confirmation ...

@arslbbt
Copy link

arslbbt commented Oct 5, 2017

any one has an answer ? about MapiExceptionSendAsDenied it outlook issue

@pial316
Copy link

pial316 commented Apr 30, 2020

OKay i fixed the problem. The trick was this link:

https://accounts.google.com/b/0/DisplayUnlockCaptcha

Please can you tell the tricks here? Having the same problem. Started using namecheap hosting and after that phpMailer stopped working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants