4

I am working on Drupal 6 my php.ini settings are:

SMTP = localhost    
smtp_port = 25    

in module in am using

function article_mail($key, &$message, $params) {    
  switch ($key) {    
    case 'invitation':    
      // note: data can be passed to this function in the $params array    
      $message['subject'] = t('EMAIL SUBJECT');    
      $message['body'] = t('MESSAGE BODY');    
      break;          
  }
}

and in code i use

$params = array(  'myVar' => 'data you would like in your message and/or subject',);    
drupal_mail('article', 'invitation', 'sanjaydev@xolva.com', language_default(), $params);

but it gives

warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\benthamdirect\includes\mail.inc on line 193. Unable to send e-mail. Please contact the site administrator if the problem persists.

Can anyone suggest where I am going wrong?

6

Try the SMTP module to send mails via SMTP:

This module allows Drupal to bypass the PHP mail() function and send email directly to an SMTP server. The module supports SMTP authentication and can even connect to servers using SSL if supported by PHP.

1

The error message indicates that no SMTP server is running on your localhost. Test this (as shown here), and install and configure a SMTP server like postfix if needed. Once your local SMTP server is tested successfully outside of Drupal, come back and test mail sending from within Drupal.

Running an own SMTP server on localhost can be meaningful for development, but for production sites, it is quite a headache nowadays to set it up so that it delivers all mail successfully rather than appearing as a spam server to major e-mail providers (GMail, Hotmail etc.). That's where the SMTP module and similar Drupal modules come in: you then can use a third-party SMTP server, which works fine if the e-mail volume is low to moderate.

1
  • This is the correct answer. "What am I doing wrong?" "With your code, nothing, but you need to have an SMTP server on your computer." – kiamlaluno Apr 2 '16 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.