Setting up SMTP in .htaccess

Tony Sharpe - June 4, 2006 - 14:31

I can add users to my site but no emails are sent to the user or to admin and no error messages. I have set the 'email address to send to' in administer/settings but can't see any other things to set up there. I gather I have to set up SMTP address in php.ini. I don't have access to that but do have access to .htaccess where I underdtand I can also do this. What exactly do I have to put in .htaccess? I have tried to search but not found the answer. I have the SMTP address for SMTP for my site. I'm using a new installation of 4.7 with 4.7.1 upgrade. PHP version 4.3.11

webform

Tony Sharpe - June 4, 2006 - 14:51

Further comment. I have installed and removed webform - I presume that that won't have messed something up - I don't know whether emails were working before.

'from' email address

Tony Sharpe - June 9, 2006 - 10:42

I now know that the reason emails are not getting through is that the correct 'from' address is not being set. This appears to be a different 'from' address to the one that appears in the header as the emails that do get through (to other addresses) display the 'from' correctly, as set in settings.
I removed the SMTP module as the host said that it only supported SMTP after POP, so the SMTP was only valid for a short time after check your emails using POP - this may be relevant to others.
The installation of webform is not related to the issue as I restored from a backup made prior to installing webform.
I don't have access to php.ini (shared host, access not allowed) so I can't set it there. I do have access to .htaccess but I don't know exactly how I would add something to that. What I have done is gone into the sites/default/settings.php file and added set_ini('sendmail_from','name@mysite.com'); which looks as though it should do the job instead of a line in php.ini. No change though - it still doesn't get the mail through. Should this take effect immediately?

.htaccess

Tony Sharpe - June 9, 2006 - 13:05

My host is now saying to check the .htaccess file. This looks like it was created by the Drupal installation. Is there something in there that affects what can be changed by set_ini()? Can something be added in there to set the from address - if so what is the syntax?

email now getting through

Tony Sharpe - June 22, 2006 - 15:19

The email problem has been resolved so I'm posting the solutions here to help others. I don't have access to php.ini (shared hosting) so, as mentioned in previous posts, it can be changed from settings.ini by adding
ini_set('sendmail_from','name@mysite.com');
into the sites/default/settings.php file.
The same information can be added to .htaccess as a php override setting under the appropriate php and apache block, e.g. within the block that starts

# PHP 4, Apache 1
<IfModule mod_php4.c>
(check your php and apache versions), then add the following
php_value sendmail_from 'name@mysite.com'.
You can check the value of this setting by writing a little test program. Create the following program in a file (using a text editor) and save as something like 'testmailfrom.php' in your site root directory.
<?php
echo ini_get('sendmail_from');
?>

then run the program from your browser by entering the address 'mysite.com/testmailfrom.php' and it should display the setting. As an aside, you can also get this and a lot of other information by changing the test program to :
<?php
phpinfo
();
?>

Having said all this, it didn't sort my problem, but it may sort the problem for some people. Eventually after lots of dialog with tech support at Hostexcellence.com they suggested to add an additional parameter to the mail() function which is in user.module. This is a call to a php function that actually sends out the mail. I added an additional parameter as '-fname@mysite.com', i.e. I added the 'from' address with a '-f' in front of it. See http://us3.php.net/manual/en/function.mail.php for further information on this including the warning under 'additional_parameters'. This did the trick but the X-warning did appear in the message header. To combat this I had to get listed as a trusted site. Once again I didn't have access to the required '/etc/mail/trusted-users' directory so had to ask tech support to do this. It didn't initially work when they said they'd done it but after a further attempt they sorted it. Everything now fine.

'from' email address

Tony Sharpe - June 22, 2006 - 15:21

Sorry, the code in my 'from email address' post of June 9th above should be:
ini_set('sendmail_from','name@mysite.com');

Thank you!!

dux0r - July 24, 2006 - 03:27

Thanks Tony so much for your discussion into setting up SMTP

I had exactly the same problem as you, everything worked but no emails were getting sent out. I am also with a shared host so no access to php.ini or any other core php files.

I did exactly as you suggested with editing the .htaccess file and settings.php and putting in the correct "From" address.

I then created your little test program and it picked up the right address in the sendmail_from variable, so I thought "hey, this is promising"

I then pressed Send/Receive in Outlook and crossed my fingers, and to my amazement, there was a confirmation email from webmaster@mysite.com

You are a champion, you've saved me many more hours of searching (I've already spent hours scouring the forums and the web for help with this problem) Most of them end up with saying "simply restart your webserver" or "edit your php.ini settings" both of which I'm of course unable to do.

You solution was simple and best of all, it worked! So thank you,

kudos to you!

dux0r

Thank you Tony Sharpe

markabrams - July 27, 2006 - 15:43

Tony, Installing Drupal and the platform that supports it on Windows has been one roadblock after another. Your ini_set('sendmail_from','name@mysite.com'); line for ...\sites\default\settings.php was the solution to the last major roadblock. My site is running and now I can play and the interface. Thank you.

Your solution should be added to the latest release and documentation.

Tony thank you!!!!!!!!!

gav240z - December 2, 2008 - 21:21

Tony, thanks so much for this, helped me a lot.

I added the line to my settings.php file and it seems to have fixed my email out issues.

Gmail / Hotmail and my own ISP account all received emails from my server.

Finally, I've had like 30 people register on my site and never get an email.

 
 

Drupal is a registered trademark of Dries Buytaert.