Link to home
Start Free TrialLog in
Avatar of john-m-calvert
john-m-calvert

asked on

php.ini & SMTP= - how do you pass username & password

My ISP account requires that I send a username & password for outbound SMTP mail. How do I get PHP to use this when executing php.mail()? The php.ini file only contains entries for the server (SMTP= ) and From: (sendmail_from= ).

I suppose that I could run a localhost SMTP service which itself doesn't need username/password but which knows how to talk with my ISP and supply username/password, but this seems like overkill. Can't PHP send this directly?

John
Avatar of carchitect
carchitect

Avatar of john-m-calvert

ASKER

Thanks for your reply. I'm aware of this link and http://www.php.net/manual/en/function.mail.php as well, neither of which mentions how to specify a username / password for outgoing SMTP mail. The php.ini has settings for host and port (SMTP= and SMTP_port= ) but what about SMTP_user= and SMTP_pwd= ?
Just add these two lines into your PHP.INI file

SMTP_user=username
SMTP_pwd=xxxxx

-Peter
does this really work....
Not according to the source.

No mention of smtp_user or smtp_pwd.

Also, the source has no code to deal with logons for smtp servers.

It does ...


sprintf(Buffer, "HELO %s\r\n", LocalHost);
snprintf(Buffer, MAIL_BUFFER_SIZE, "MAIL FROM:<%s>\r\n", RPath);
snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT TO:<%s>\r\n", token);

No USER or PASS.

So, basically not supported.

Richard.
A solution would be to do the whole job manually with sockets.

That way you are in TOTAL control. But that would be wheel re-invention.

Do any of the mail classes (MIME_HTML, etc) support secured SMTP access?
Thank you Richard for that informed answer. My original mention of "SMTP_user=" and "SMTP_pwd=" was pure wishful thinking, although perhaps that wasn't clear to the other respondents.

Could you add one more detail to your reply? You mention referencing the source code. Source for what module exactly, and where can mere mortals view this?
Source of PHP.

You can download it from www.php.net (or the mirrors).

When you unpack the source, look in ...

php-4.3.1\win32\sendmail.c

Richard.
ASKER CERTIFIED SOLUTION
Avatar of pcaylor
pcaylor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you pcaylor for this sample PHP script. It works great.

I'm a little rusty with my C, and I'm totally new to PHP, but if I'm reading the PHP C source code correctly, the critical function is SendText()in php-4.3.1\win32\sendmail.c which has the same socket conversation as the above PHP sample. So, if an ambitious C programmer wants to extend PHP to offer an authenticated version of mail(), that would be super duper! I'm not quite there yet as I don't have the appropriate build environment for the PHP C source code, but maybe next month ;)

All that is needed is a few lines of C and a convention as to where to retrieve the usr/pwd from in order to send the SMTP command and reply on the socket:
AUTH
username
password

John
Following pcaylor's PHP example SMTP socket code I was able to hack the PHP source code in C and add authentication to the mail() function. Thanks again for pointing me in the right direction.
Can you share the PHP Source mods? Or have you passed it up to cvs?