Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP hates me!

Featured Replies

Hello,

 

I've just started trying to learn PHP & MySQL with the 'Head First' series of books.

 

I managed (I think) to install PHP & MySQL properly and have nearly reached the end of Chapter 1 of the book. I have created my first PHP script to generate a confirmation HTML page with some form data.

 

The last step is to get the PHP to send myself an email with this form data as an email message. The only thing is, I don't get an email.

The confirmation HTML page displays fine with all the information and no error reports, but the email is totally non-existant, as though I hadn't asked it for one.

 

This is my PHP code:

 

<html>

<head>

<title>Aliens Abducted Me - Report an Abduction</title>

</head>

 

<body>

<h2>Aliens Abducted Me - Report an Abduction</h2>

 

<?php

$name = $_POST['firstname'].' '.$_POST['lastname'];

$when_it_happened = $_POST['whenithappened'];

$how_long = $_POST['howlong'];

$how_many = $_POST['howmany'];

$alien_description = $_POST['aliendescription'];

$what_they_did = $_POST['whattheydid'];

$fang_spotted = $_POST['fangspotted'];

$email = $_POST['email'];

$other = $_POST['other'];

 

$to = 'myemailaddress@host.com';

$subject = 'Aliens Abducted Me - Abduction Report';

$msg = "$name was abducted $when_it_happened and was gone for $how_long.\n" .

"Number of aliens: $how_many\n" .

"Alien description: $alien_description\n" .

"What they did: $what_they_did\n" .

"Fang spotted: $fang_spotted\n" .

"Other comments: $other";

mail($to, $subject, $msg, 'From:' . $email);

 

echo 'Thanks for submitting the form.<br />';

echo 'You were abducted ' . $when_it_happened;

echo ' and were gone for ' . $how_long . '<br />';

echo ' Number of aliens: ' . $how_many . '<br />';

echo 'Describe them: ' . $alien_description . '<br />';

echo 'The aliens did this: ' . $what_they_did . '<br />';

echo 'Was Fang there? ' . $fang_spotted . '<br />';

echo 'Other comments: ' . $other . '<br />';

echo 'Your email address is ' . $email;

 

?>

 

</body>

</html>

 

I am running a PowerPC G4 laptop with Mac OSX (v10.5.6) and I'm running my PHP on the Localhost server.

 

I should point out that I have NO experience or idea what I'm doing when it comes to 'Terminal' commands or editing/modifying files such as the PHP.ini file (which I believe may be where the problem lies from what I've read).

Everything I've found so far gives examples of changes that should be made either in the PHP.ini file or in the PHP code itself but assumes you kind of already know what you're doing. I have NO idea, really, if you say type 'this' I'll just type it but have no idea why or what 'this' does.

 

I'd be extremely grateful if anyone can help me to get this to work so I can continue learning about PHP. Also if you know of any good refferences about 'root' stuff i.e Terminal commands so I don't unintentionally kill my computer that'd be nice too!

 

Thank you in advance,

Rockstar79

Hi

 

if you are testing this locally, then it wont send the email. you are better off testing this online.

 

you would have to set a mailserver locally for this to work.

 

Pat

  • Author
Hi

 

if you are testing this locally, then it wont send the email. you are better off testing this online.

 

you would have to set a mailserver locally for this to work.

 

Pat

 

ah I see...I didn't know that, and the book doesn't tell you that either!

 

I wasn't exaggerating when I said I knew nothing about this. I really appreciate the help.

 

Is this all stuff I should already know about BEFORE trying to learn PHP or is it a 'find out as you go' kind of thing?

 

Thanks Pat24

If you have a smtp server, you don't need to setup a local mail server. You just need to add your e-mail settings to your PHP.ini file on your local server!

 

[mail function]
; For Win32 only.
; SMTP = smtp.something.something

 

It should look like this. Just remove the ";" before SMTP and specify your smtp server address.

 

I hope this work (if you have a mail server elsewhere)!

  • Author
If you have a smtp server, you don't need to setup a local mail server. You just need to add your e-mail settings to your PHP.ini file on your local server!

 

[mail function]
; For Win32 only.
; SMTP = smtp.something.something

 

It should look like this. Just remove the ";" before SMTP and specify your smtp server address.

 

I hope this work (if you have a mail server elsewhere)!

 

Hi Suhm, and thanks for your reply to my post.

 

I tried doing exactly as you said but unfortunately it didn't work. My email is set up to use with AOL, and I set my SMTP address accordingly, using the account information found in Mail > Preferences > Account Information.

*I used the 'outgoing mail server (SMTP)' address. I'm assuming this is the correct one to specify?

 

As an extra thing, I also tried specifying the smtp_port number in the php.ini file as I read that '25' is the default setting. In my Mail settings, my smtp port is set to something different. Sadly changing this made no difference either.

 

I'm at a complete loss as to how to get this to work locally. I'm just learning and playing around with PHP at the moment and I'd rather not spend money I don't have on webservers/hosting. If I have to then I have to, but I would ideally like to have a local environment to play in, and one that is VERY simple and easy to use.

Hi Suhm, and thanks for your reply to my post.

 

I tried doing exactly as you said but unfortunately it didn't work. My email is set up to use with AOL, and I set my SMTP address accordingly, using the account information found in Mail > Preferences > Account Information.

*I used the 'outgoing mail server (SMTP)' address. I'm assuming this is the correct one to specify?

 

As an extra thing, I also tried specifying the smtp_port number in the php.ini file as I read that '25' is the default setting. In my Mail settings, my smtp port is set to something different. Sadly changing this made no difference either.

 

I'm at a complete loss as to how to get this to work locally. I'm just learning and playing around with PHP at the moment and I'd rather not spend money I don't have on webservers/hosting. If I have to then I have to, but I would ideally like to have a local environment to play in, and one that is VERY simple and easy to use.

 

Argh no... AOL... do aol force you to authenicate outbound emails?

 

I didn't check, but what are you using in your local enviroment... if you have php try using sendmail, here's something to get you started :)http://www.daniweb.com/forums/thread38784.html#

  • Author
Install this bad boy - Test Mail Server Tool

 

I use it on my local WAMP installation, oh and it's free too. B)

 

Thanks for your response Sam G. The 'test mail server tool' looks like a great tool but unfortunately, in my case, it won't work as I'm running Mac OS X (Leopard) and this is an application for Windows.

Thanks for your response Sam G. The 'test mail server tool' looks like a great tool but unfortunately, in my case, it won't work as I'm running Mac OS X (Leopard) and this is an application for Windows.

 

Any joy with sendmail?

  • Author
Any joy with sendmail?

 

Hi Madcatjack...I've just been trying it out and sadly 'sendmail' doesn't work either.

 

I'm not completely ruling out the possibility that AOL being my SMTP server might be hindering things a bit...I don't like AOL, but just haven't changed it yet :rolleyes: Of course, this is completely unfounded and me just guessing and clutching at straws.

 

I'm beginning to run out of options. I may have to get a 'real' website hosting service to do this stuff on as Pat24 said. I'm just amazed that from ALL the forums and articles I've read (not just this one) it seems to work for some people and not others, and there are several different ways of getting this to work? Shouldn't just either work or not work? As I said, I don't know much about his at all as I'm just learning, but it seems very confusing. The PHP code part of it actually seems like a nice relief to think about by comparison to getting this email thing to work lol

I tried doing exactly as you said but unfortunately it didn't work. My email is set up to use with AOL, and I set my SMTP address accordingly, using the account information found in Mail > Preferences > Account Information.

*I used the 'outgoing mail server (SMTP)' address. I'm assuming this is the correct one to specify?

 

I'm not quite sure that you can use AOL as your mail server. I don't know AOL that well, so correct me if i'm wrong!

 

Sam, nice tool! Never heard of it...

 

- Peter

Ahh I didn't read the bit where you said you are running OS X... My bad...

  • Author

Ok, it's now day 5 of me trying to get the mail() function to send me an email I actually recieve by running my PHP on my local host server (Apache).

 

I've read numerous forum posts all of which seem to have different recipes for getting it to work but none of them work for me, although admittedly, with my level of inexperience I could be entering in the wrong SMTP address or something equally stupid.

 

I've changed the php.ini file to:

 

[mail function]
; For Win32 only.
SMTP = my smtp outgoing mail server address
smtp_port = 25

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = sendmail -t -i

 

and I changed the main.cf file to:

 

# INTERNET HOST AND DOMAIN NAMES
#
# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
#
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld

*I changed 'myhostname = host.domain.tld' to 'myhostname = me.mailserver.co.uk'

 

I'm not entirely sure which SMTP value to specify. Is it my outgoing mail server address as listed in my MAIL > Preferences?

Also, when speaking about host.domain.tld....what is 'host' and what is 'domain'? Can these be smtp.aol.com or mail.gmx.com, for example?

 

Pat24 says this can't be done through my localhost server, and that I should test my PHP online with a proper web host. I'm starting to think this is the ONLY way, although various other forum posts lead me to think it can be done and that something on my computer just isn't configured properly.

 

I'm at a total loss and as you have guessed I don't really know what I'm doing when it comes to mail servers, terminal commands or editing system files etc

 

If someone could offer a diffinitive yes you can or no you can't I'd be so grateful. I just want to be able to get the php mail() function to send me an email so I can continue my studying.

 

Thank you all in advance

PS AOL reaaaaaaaaaaaaly suck :(

 

See this to get the right port to the AOL servers (587)

 

You may need to pop authentication details into php.ini

 

Man AOL suck :(

  • Author

Thanks madcatjack, I didn't know that and will play around with my port number.

 

I agree...AOL (or AOHell as I like to call it) does suck. I just set up a free gmx email account to see if that made any difference, but if they too block port 25 then obviously I'll have the same problem.

 

Just to clarify, are you saying that using an email account, such as gmx, will work? For example, if I specify in the php.ini file:

 

SMTP = mail.gmx.com (outgoing mail server)

smtp_port = 587 (for example)

 

Just to try and narrow things down a little, if I specify the SMTP address as you said in an earlier post AND I set my port number to one that isn't blocked, should that work without making any other alterations anywhere else? I've read that you have to make changes to the 'main.cf' file, the 'hostconfig' file and the 'httd.conf' file as well as entering some 'command lines' in the terminal?

 

Obviously, not really knowing what I'm doing, this gets a bit overwhelming very quickly. I'm just trying to find a little clarification so I can go through and check things off one at a time.

 

Thanks again

It isn't just the mailserver that is blocking port 25, it is your ISP (internet service provider). So you cant send data on port 25 from your computer - to any mailserver.

 

587 will work with the aol email server I think.

 

Other mail servers will need to be able to accept emails on port 587.

 

My main suggestion would be to get the hell rid of AOL tomorrow ;)

  • Author

I've just about tried everything I can think of or have been told by others and STILL no joy.

 

Something I have discovered though is this:

 

While watching the mail.log in a terminal window when submitting my form I get some error messages (depending on which mail server I'm trying to use) that confirm the problem is at the recieving end and NOT with the PHP actually sending or trying to send an email.

 

With AOhell, I changed the port number to 587 as recommended. This still doesn't work, but in the mail.log it gives a URL for the error. This error is that AOL doesn't accept email from dynamic and/or residential IP address. These IP address get put on a block list at www.spamhaus.org. You can apparently have your IP address removed by your Internet Service Provider.

 

Hotmail accounts also use the spamhaus filter.

 

When I try this with my gmx account (free email service similar to hotmail) I don't get the 'spamhaus' error. This time I get an error saying Macintosh postfix/smtp[350]: ***********: lost connection with mx0.gmx.net[***.***.**.***] while receiving the initial server greeting

 

Unfortunately I haven't derrived any solution from these error messages, but I thought it may be useful to someone or perhaps even give someone a clue as to how I can solve my problem.

 

Thanks for your help and patience :)

AOL block port 25 on all out bound traffic. This is to help cut down on spam caused by mail bots.

 

When you use port 537 you will need to authenticate against the server correctly in your PHP, otherwise it will fail.

 

AOL simply should not be used as a test bed - or at all in my opinion. If you are serious about getting this working - just get some hosting, you will need it anyway for when the site goes live.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.