Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-17-2004, 05:01 PM   #1 (permalink)
Epsilon
Regular Contributor
 
Epsilon's Avatar
 
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 127
Epsilon is on a distinguished road
Specifying SMTP server for PHP mail()

I'm writing a script for use on a Windows web server and I can't get it to send mail. The host says you have to specify the SMTP server for the domain name, but in all the docs I've looked at I can't figure out the right syntax.

Here's my test script:
Code:
ini_set("SMTP","mail.domain.com");

if (mail("me@mydomain.com","This is a test","This is the body","From: user@domain.com\r\nContent-type: text/plain\r\n\r\n"))
{
print "Success";
}
else
{
print "Failed";
}
I've tried several things, but no luck. All the PHP documentation I can find talks about setting the SMTP server in php.ini, which makes perfect sense, but this is a virtual hosting account and I can't modify php.ini. There has to be some way to set it in the script.

Has anyone had luck using mail() on Windows?
__________________
--Epsilon--
Epsilon is offline   Reply With Quote
Old 03-17-2004, 06:14 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
i've never done it that way .. i've always edited it in the php.ini , .. then i restart the web server.
__________________
Mike
sde is offline   Reply With Quote
Old 03-18-2004, 12:20 AM   #3 (permalink)
Epsilon
Regular Contributor
 
Epsilon's Avatar
 
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 127
Epsilon is on a distinguished road
Well, after a lot more reading and searching and trial and error I figured it out.
Code:
ini_set("SMTP","mail.domain.com");
ini_set("sendmail_from","user@domain.com");

if (mail("me@mydomain.com","This is a test","This is the body","From: user@domain.com\r\nContent-type: text/plain\r\n\r\n"))
{
print "Success";
}
else
{
print "Failed";
}
They require you to specify the SMTP server AND a valid From address for the domain, and the 'From:' setting in the header isn't good enough. You have to use ini_set() for both.

IMO as a programmer I think this is a load of BS. Basically the web host is forcing me to use ini_set() to override both of these settings during runtime of the script because they intentionally set them incorrectly in their php.ini file. Apparently they feel this gives them better security with regard to spammers. Maybe so, but I spent about 6 hours troubleshooting it and no one in their tech department could figure out what the problem was. I ended up stumbling upon the solution through trial and error.

Virtual hosting sucks, and Windows servers suck. And the two of them together are a catastrophe. Just my opinion.
__________________
--Epsilon--
Epsilon is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Server config / .htaccess DavH27 Lounge 12 08-26-2004 05:16 PM
E mail Bombed NOT FOR KIDS (Rated R) Eyelfixit Lounge 10 07-09-2003 10:13 AM
Windows server 2003? CaN Opener Lounge 3 03-24-2003 05:22 AM


All times are GMT -8. The time now is 02:11 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting