This topic is locked
[SOLVED]

Send Email with SMTP Settings

6/12/2024 2:57:39 PM
PHPRunner General questions
P
PK author

I have been using my gmail account to send emails from my app. And before I was able to do this I had to go to my google account and "allow less secure apps to connect" and this has worked fine with no problem,
Now I want to use my company email so I used Sergey's solution from here
In AfterAppInit I put this:

img alt

And I try to send the email using the same method as before

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'htmlbody' => $msg, 'fromName'=> $fromName, 'from'=>$from));
if(!$ret["mailed"])
$result["Err"] = "Error";

But this does not work. I get an error in the afterServer of my button about "undefined Err". "Err" is the variable from here $result["Err"]
The credentials I used for the smtp settings is the same one I use in my email clients (microsoft outlook) and there is no problem with sending and receiving from there
Is there something equivallent to "allow less secure apps to connect" on my cPanel I need to set to allow emails to go through?

Thanks

Percy

M
Mark Kramer 6/12/2024

If you are using Office 365 (just a wild guess when you said "company" email) the same scenerio like your gmail, it will have to be set to use less secure via your admin section on 365. I would also try sending with out ssl to test. be sure to change you ports when you turn off ssl. I run into this a lot with scannner/copiers .

P
PK author 6/13/2024

Thank you for your response.
My corporate email is actually regular domain based private email hosted by Godaddy.
I found out (after I came in fresh this morning) that I was using the wrong port (I had put in the incoming instead of the outgoing port) Corrected now and error is gone.
BUT the email still doesnt send. No error in my app and I get a success swal but the email does not arrive. S I am thinking it really has something to do with my hosting maybe?? I cant find anything on my cPanel that "allows less secure apps to send emails". There is a feature that allows me to generate an api token but. (if that is the solution), how do I use the token in PHPRunner.

img alt

Thanks again

Percy

M
Mark Kramer 6/13/2024

Cool!

Good to know. I may run into this scenerio myself.

P
PK author 6/14/2024

Mark Kramer,
I think you misunderstood my last post. It was a question not a statement. lol.
So the error I was having is gone (becuase I was using the wrong port before) but the email still does not go through. Never arrives in the in box even thoough the app does not give any error anymore.
So I was asking if there might be something else I need to do for instance create an API token from the hosting cpanel.
And even if I do, where will I put it?
Because I think mail funtion in PHPRunner only needs:

strSMTPUser
strSMTPServer
strSMTPPort
strSMTPPassword
strFromEmail
SMTPSecure

No API token parameter as far as I can tell.
Maybe the solution is not about the API token, maybe its something else. The details I am using for the parameters above in PHPRunner, is the same one I use in my mail client (Microsoft Outlook) and it works there so I am confused.

Any ideas?

Thanks
Percy

fhumanes 6/14/2024

Hello ,

In my mail client, I have a Microsoft account and these are the parameters that I have configured.

img alt

Greetings,
fernando

fhumanes 6/14/2024

Hello ,

In my mail client, I have a Hostinger account and these are the parameters that I have configured.

img alt

Greetings,
fernando

M
Mark Kramer 6/15/2024

Are you using Godaddy's office 365 for mail? If so there are some settings that must be turned on. Read this article https://www.godaddy.com/help/set-up-microsoft-365-email-with-smtp-on-a-multifunction-device-41962

P
PK author 6/15/2024

Thanks Fernando and Mark,
For Fernando's comment I have tried with SSL and withious SSL using the same credentials on the cPanel (same as I use in my mail client) I have setup the same email on my phone and laptop and it works fine so I dont thing the credentials are the issue.

Mark, redarding your question, I am not using Office 365. Seems like a normal hosting package. Screen shop from my Godaddy account

img alt

I also just found this (below) in my cPanel saying the SSL cerificate is expired?

img alt

If this is the issue, then the email on my phone and laptop should not work where I am using SSL/TLS in both, but it works there.

C
cristi 6/15/2024

Why don't you debug the smtp as described here

Or you can use one of the techniques described here

P
PK author 6/15/2024

I cannot believe how dumb I have been in the last few days.
I used cristi's suggest and I found the problem. I started developing the application using a gmail account and I hardcoded the "fromEmail" in my pages where email needs to be sent.
Then when I decided to change the email acount from gmail to my corportate account I changed the smtp settings in my db but the "fromEmail" was still the old (hardcoded) gmail one.

So now I have changed all pages to lookup all credentials including the "fromEmail" from my db.

Problem Solved. Thanks you all for your help and I feel terrible for wasting your time.

Thanks again!!

Percy