I’ve been using Linux ever since I became a CS major at Georgia Tech five years ago. I’ve compiled my own kernels, maintained Apache and MySQL, and written custom IPTable’s; I’ve even setup printing AND scanning with modern hardware. But not once have I ever come close to setting up a working mail server.
On second though, I think I may have come close once. I sent out an email to myself and then sat there at my GMail inbox hitting refresh, waiting to receive the message. About five minutes later I found it in the spam folder and started reading about reverse IP pointers and DomainKeys. My brain started to hurt and in the end, I was sending messages through godaddy.com’s email servers and hoping most of my customers got their emails.
Now that GMail for your domain has arrived (if you’re a lucky beta winner, that is) it’s like hiring a world-class email server engineer and paying them nothing. It takes a little work because of GMail’s security requirements, but you end up with a rock solid email server that won’t send messages straight into spam folders.
First, download the standard PHPMailer libraries (version 1.73). The only thing you have to modify is the class.smtp.php file. Open it and go down to about line 683, in the Quit() member function. Comment out everything between the fputs() that sends the “quit” command and the if statement surrounding $this->Close() except for $rval = true;. The reason this works is unknown to me, but every time I tried to read from the socket after sending the “quit” command I got a lot of garbage.
Now just use the following settings:
$mail->From = '***@&&&.com';
$mail->Mailer = 'smtp';
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = '***@&&&.com';
$mail->Password = '***';
Replace the *’s and &’s for real values and you’re all set.
Hi,
Your article seems very interesting, but I can’t seem to get it working. Can you post or send me class.smtp.php and a sample php file that sends out email? Thanks.
I’ve just updated my post, try commenting back in the $rval = true; line in the Quit() member function.
Hi,
Your article also seems very interesting to me, but I to can’t seem to get it working. Can you post or send me class.smtp.php and a sample php file that sends out email?
Thanks.
Hello.I’m also trying on it but nothing happens. do u mind sending me a sample as well? thanks~
does this work for anybody? is this even real?
Does anybody get this error?
Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known (is your IPV6 configuration correct? If this error happens all the time, try reconfiguring PHP using –disable-ipv6 option to configure) in /home/username/public_html/class.smtp.php on line 106
Warning: fsockopen(): unable to connect to ssl:25 in /home/username/public_html/class.smtp.php on line 106
There has been a mail error sending to John
sent…
Didn’t work for me either. I get:
Warning: fsockopen() expects parameter 2 to be long, string given in .\phpmailer\class.smtp.php on line 105
Mailer Error: Language string failed to load: connect_host
so I hacked class.smtp.php and entered in the parameters for fsockopen manually. very messy but got it to work!
hi, james, can you send me the files necessary for it to work? my email is johnsmith19 at hotmail dot com. Thanks!
I did the same as James Kelly and I got it to work!
on line 104 I inserted this:
//HACK!!!!
$host = ’ssl://smtp.gmail.com’;
$port = 465;
// END HACK!!!
Also, needed to supress a warning on line 1036.
used to be:
while($str = fgets($this->smtp_conn,515))
now it is:
while($str = @fgets($this->smtp_conn,515)) //ALTERED supress warning with @
Cheers!
I forgot that I had put some debugging echos in so my line numbers may differ from yours by about 3. To clarify, insert the code:
//HACK!!!!
$host = ’ssl://smtp.gmail.com’;
$port = 465;
// END HACK!!!
before this code:
#connect to the smtp server
$this->smtp_conn = fsockopen($host, # the host of the server
$port, # the port to use
$errno, # error number if any
$errstr, # error message if any
$tval); # give up after ? secs
Hi to all, I get this error:
Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport “ssl” - did you forget to enable it when you configured PHP?) in C:\wamp\www\email\phpmailer\class.smtp.php on line 113
any idea??
I did what Adam Says: and it worked just fine. Before I was getting the open socket error and it said something about a language stream. I also have mine on a https connection, I don’t know if that makes a difference.
I can’t seem to get this to work. Could anyone please post a working class.smtp.php file here? Minus your personal smtp info of course.
I got this working! Thanks!
I found out the problem. Uncomment the line extension=php_openssl.dll
in the file php.ini.
Then php will allow ssl.
The reason we put the hack because phpmailer splits the string
“ssl://smtp.google.com”
into
$host = “ssl” and $port = “//gmtp.google.com” with the separator “:”.
This is because sometime we will put the url like:
“smtp.google.com:465″.
The reason we put the hack code because phpmailer splits the string “ssl://smtp.google.com”
into
$host = “ssl” and $port = “//gmtp.google.com” with the separator “:”.
I guess the author of phpmailer does not expect people will make the string like that. He/She only expects people to input something either like:
address.without.colon
or
address.without.colon:port
i have done all the changes but i still encounter thsi error:
Fatal error: Maximum execution time of 60 seconds exceeded in D:\wamp\www\class.smtp.php on line 1024
can anypne please help???
I have a local server and have installed php. I have downloaded the above files but I don’t understand where I need them. Do I put them in the PHP directory? The changes made to the class.smtp.php I think I made correctly but now I don’t know where to save that file and I don’t know where to add the settings for “From” “mailer” etc. I am trying to learn how to do this and just need someone to explain a few things to help get me up to speed. I know it is asking a lot but if someone would be willing to work with me I would sure appreciate it.
Kind regards,
Marcus
It looks like Gmail has since changed the port to 587 (http://mail.google.com/support/bin/answer.py?answer=13285&query=smtp&topic=&type=f&ctx=search). I’ve had a bit of experience with PHP and have made the changes mentioned above and still no dice.
I can configure Thunderbird to send through my account no problem, but doing it from my webserver still doesn’t work. I’ve got SSL enabled, made sure my gmail account is configured properly and I’m getting this error:
“class.smtp.php (105): fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: No such host is known.”
This is when it’s calling fsockopen(ssl://smtp.gmail.com, 587, x, y, 10). Anyone have any other ideas?
hi there, can anyone send me the needed files to be able to run it, i’ve tried the script above,but i get too many errors…
thanks…
Thanks so much. I got this to work after a little hacking. When I copied the code from you site, the ‘ ended up as ` so it was trying to eval my email address. Might be a good idea to point that out? Thanks though.
Hello all;
I have been trying to get this mail() to work for a little while now. I used to get some PHP syntax errors regarding class inheritance and some class instantiations as well as undefined functions such as isSMTP() and i believe another was Delay() or something…. all that is now fixed i have PHP5.0 and Apache2.2.6 on WinXP. i used to get the fopensoc() error but not anymore I have made sure openssl is configured properly ( meaning the dll is uncommented in the php.ini file) and included host and port values in the class.smtp.php file as follows:
$host = ’smtp.gmail.com’;
$port = 465;
i have noticed that leaving ssl:// out and keeping it in single rather than “” quotes will resolve the fopensoc() issue.
Now i used to get the 60 secs had passed timed out error.. but not anymore i think it depends on the script i am using to mail the thing with.. According to the script at the top of this page i don’t see anything the page goes blank and I YET TO receive an email….
please any help is greatly appreciated… thank you…
stualnakib@hotmail.com