Shoutbox

Trouble sending email from PHP - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Trouble sending email from PHP (/showthread.php?tid=92777)

Trouble sending email from PHP by Spunky on 11-03-2009 at 02:33 PM

Ok, a bit of background first.

My boss at work asked to make a system to put bookings onto for various things (meetings, car parking spaces, contractors, company vehicles etc). I made it using PHP and mySQL and hosted it on www.freehostia.com, which seems to be quite a fully featured web host considering it's free. Everything was all working fine and the system took off quite well.

I was later asked to add a maintenance request form and integrate it, which didn't take much work because of the already exisiting framework for it. Now, he's asked me if it's possible to send him an email when a job is requested. Sure enough, I set about it... now this is where things get complicated.

I can't use PHP's mail() as we don't have an SMTP server to use (They're pushing to make it all completley free btw) and the hosting doesn't provide one.

I can't seem to use an external site's SMTP (such as smtp.gmail.com) as I can't edit my php.ini file on the web host.

I can't use the college system to send it as we are using an exchange server and have quite a strict policy on what we can do (I can't even connect an FTP client to a server from inside the college as I don't have permission, even though I actually have)

I've tried using an example demonstrating fsockopen to send the email, but it fails everytime with error 13 (permission denied), despite php.info reporting allow_open_urls to be true.

I need an idea how to just send an email, for free, from PHP, where I can spoof the headers to appear to be sent from within our domain and to set the reply-to address.

Any ideas? :s


RE: Trouble sending email from PHP by matty on 11-03-2009 at 02:54 PM

PHPMailer? http://sourceforge.net/projects/phpmailer/files/p...er%20for%20php5_6/


RE: Trouble sending email from PHP by Spunky on 11-03-2009 at 03:02 PM

I did try it, but no luck. It always says the message sent though, which makes me think the SMTP servers I'm using are at fault.

I think that's going to be the biggest problem. I'm not going to be able to use one for free. If I didn't have to keep switching between windows and ubuntu, I'd have set it up on my own local machine


RE: Trouble sending email from PHP by MeEtc on 11-03-2009 at 04:06 PM

Why are you using that free site instead of the webspace I gave you?


RE: Trouble sending email from PHP by Spunky on 11-03-2009 at 08:14 PM

It's a work thing. spunkylovemuff.co.uk wouldn't have looked very good, and I didn't want to have a sub-domain. I settled for a custom sub-domain that I can use for all work stuff.


RE: Trouble sending email from PHP by Jarrod on 11-03-2009 at 09:06 PM

It looks like they have python setup you might be able to knock something up in python to send the mail then have your php just call the python function

example

python code:
#!/usr/bin/env python
import cgi
import smtplib
fields=cgi.FieldStorage()

print "Content-Type: text/html"#the mime header
print


print """
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>sender</title>
</head><body><center>"""



if 'message' in fields:
    message=fields["message"].value
else:
    message=None
   
if 'to' in fields:
    to=fields["to"].value
else:
    to=None


if bool(to)==True and bool(message)==True:
    server = smtplib.SMTP('smtp.gmail.com')
    server.set_debuglevel(1)
    server.ehlo()
    server.starttls()
    server.ehlo()
    #fill in those 3 fields then you can call like email.cgi?to=address&message=test
    server.login("""~~~~~~~~gmailuser~~~~~~~""", "~~~~Gmail password~~~~~~~~~")
    server.sendmail("~~~~from address~~~~~~~~~~", to, message)
    try:
        server.quit()
    except:
        pass


print"""
</body>
</html>"""


RE: Trouble sending email from PHP by Spunky on 11-04-2009 at 10:45 AM

Lol. Tried your idea Jarrod:

Forbidden
You don't have permission to access /email.cgi on this server.


Changed CHMOD and it "sent"... Never received it though. I can only assume that Gmail stopped allowing external SMTP use at some time =/


RE: Trouble sending email from PHP by Jarrod on 11-04-2009 at 11:01 AM

quote:
Originally posted by Spunky
Lol. Tried your idea Jarrod:

Forbidden
You don't have permission to access /email.cgi on this server.


Changed CHMOD and it "sent"... Never received it though. I can only assume that Gmail stopped allowing external SMTP use at some time =/
tested it it works check your spam folder

edit you don't have to use gmail, universities often have smtp servers which will act as relays
RE: Trouble sending email from PHP by Spunky on 11-04-2009 at 11:40 AM

Where's your script located and I'll give it a try... Still not working here...


RE: Trouble sending email from PHP by Jarrod on 11-04-2009 at 11:46 AM

I checked it again, it def works, i don't need ppl abusing my gmail account or my macbook so check your pm's


RE: Trouble sending email from PHP by Spunky on 11-04-2009 at 12:08 PM

Hmmm, I don't know. It's failing at setting up the SMTP server. I'm doing a check now to see if the smtplib module is installed on the server.


RE: Trouble sending email from PHP by Jarrod on 11-04-2009 at 12:13 PM

should be it's a standard module, might be a problem if the server is running python 2.1 though


RE: Trouble sending email from PHP by WDZ on 11-04-2009 at 09:48 PM

From what I could tell from the freehostia forums, free accounts aren't allowed to send mail. =p

http://forum.freehostia.com/viewtopic.php?t=9642
http://forum.freehostia.com/viewtopic.php?t=9270


RE: Trouble sending email from PHP by Jarrod on 11-04-2009 at 10:36 PM

I came across this http://sendible.com/api which should in theory be what you need, they have a free plan but it embeds advertising in the email, so it might not be ideal from that sense, you could always host the mail sending script on another server, but if you were to do that it would probably suffice to write it in php


RE: Trouble sending email from PHP by MeEtc on 11-05-2009 at 12:50 AM

Contact me on WLM Spunky, I might have an idea for you.