Frage

I have an older PHP system that uses SMTP commands for mail. We are switching over to gmail and I need to authenticate. I can connect to the server. Unfortunately, I get a 530-5.5.1 Authentication Required. Learn more at" message when I send the MAIL FROM command in my PHP code.

if (fputs($this->Socket,  "MAIL FROM: \"admin\" <admin@yourdomain.com>\r\n")<0){ 

I cannot find a clear example of adding authentication. I read at http://www.faqs.org/rfcs/rfc2554.html that I must add AUTH= to my MAIL FROM command. I am having troubles interpretting what to put in the AUTH=

Examples:
   C: MAIL FROM:<e=mc2@example.com> AUTH=e+3Dmc2@example.com
   S: 250 OK

Do you know the format of authentication?

War es hilfreich?

Lösung

There are several ways to do SMTP authentication, but one of them is to use the SMTP AUTH LOGIN command. The transcript of the session would look like this:

host: 220 banner_here
client: EHLO StephaniePC
host: 250-name.of.host hello [clientip], pleased to meet you
host: 250-AUTH LOGIN PLAIN
host: 250 OK
client: AUTH LOGIN
host: 334 VXNlcm5hbWU6
client: am9lc21pdGg=
host: 334 UGFzc3dvcmQ6
client: bGV0bWVpbg0K
host: 235 2.7.0 Authentication successful
client: MAIL FROM: <sender@senderdomain.tld>
host: 250 2.1.0 Ok
client: RCPT TO: <recipient@recipientdomain.tld>
host: 250 2.1.0 Ok
client: DATA
host: 354 End data with <CR><LF>.<CR><LF>
....

The encoded strings that you see above are base64 encoded. If you have a mail client that is capable of logging, you can try sending a message through gmail, and the transcript of the session should look like the transcript above.

FYI, instead of writing code yourself to do SMTP authentication, you might want to use phpmailer. phpmailer can do SMTP authentication, and it's very lightweight and easy to use.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top