Whitespace creates connection error
nelovishk - May 20, 2009 - 22:13
| Project: | SMTP Authentication Support |
| Version: | 6.x-1.0-beta3 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | oadaeh |
| Status: | active |
Jump to:
Description
The error:
In the /admin/settings/smtp, if the SMTP server field has spaces before of after the value, the SMTP module will be unable to connect, throwing the following error:
SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
SMTP Error: Could not connect to SMTP host.
The (temporary) solution
The error is easily solved: simply remove any whitespace in the field, and things work fine.
I'm not sure if the other fields suffer from the same problem.
I guess a simple trim() would fix things, but don't know where that should be.

#1
Thanks for the update. Probably the port number could benefit from a trim() function, as well. I'll include the fix in the near future, but for those playing at home, I changed this:
$mail->Host = variable_get('smtp_host', '') .';'. variable_get('smtp_hostbackup', '');$mail->Port = variable_get('smtp_port', '25');
to this:
$mail->Host = trim(variable_get('smtp_host', '')) .';'. trim(variable_get('smtp_hostbackup', ''));$mail->Port = trim(variable_get('smtp_port', '25'));
at around line 758 of smtp.module.