Using mail()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Using mail()

Post by aceconcepts »

Hi,

I have a rather annoying/weird problem.

Here is my sacript that I use to send an email:

Code: Select all

$to="me@mysite.com";
$massage="hello, this is a test!";
$from = "someone@somewhere.com";
	$headers = "MIME-Version: 1.0\r\n";
	$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
	$headers .= "Content-Transfer-Encoding: 7bit\r\n";
	$headers .= "From: " . $from . "\r\n";

//SEND THE EMAIL
	mail($to,$subject,$message,$headers);
Here is the problem:

My web site (e.g. mysite.com) has a contact form using the above script.

When a message is sent from this script to me@mysite.com, I do not receive anything at all.

However, when the same script is used to send an email to me@mysite.com, BUT from a different domain i.e. anothersite.com, I receive the message just fine.

Any ideas why this may happen?

I know it could be a number of things, but would appreciate a few pointers.

Cheers[/b]
RhapX
Forum Commoner
Posts: 30
Joined: Mon Dec 05, 2005 5:24 pm
Location: Seattle, Washington

Re: Using mail()

Post by RhapX »

You have a spelling error. $massage when defined is spelled differently than what you used in the mail() function which was $message
aceconcepts wrote:Hi,

I have a rather annoying/weird problem.

Here is my sacript that I use to send an email:

Code: Select all

$to="me@mysite.com";
$massage="hello, this is a test!";
$from = "someone@somewhere.com";
	$headers = "MIME-Version: 1.0\r\n";
	$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
	$headers .= "Content-Transfer-Encoding: 7bit\r\n";
	$headers .= "From: " . $from . "\r\n";

//SEND THE EMAIL
	mail($to,$subject,$message,$headers);
Here is the problem:

My web site (e.g. mysite.com) has a contact form using the above script.

When a message is sent from this script to me@mysite.com, I do not receive anything at all.

However, when the same script is used to send an email to me@mysite.com, BUT from a different domain i.e. anothersite.com, I receive the message just fine.

Any ideas why this may happen?

I know it could be a number of things, but would appreciate a few pointers.

Cheers
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Oops my mistake.

I typed this in the web editor directly. It does actually say "message "in the original script.

So any other suggestions?
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

no subject?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Apologies, I think I was half asleep when i wrote this.

Here is an updated version:

Code: Select all

$to="me@mysite.com";
$subject="Test Email";
$massage="hello, this is a test!";
$from = "someone@somewhere.com";
        $headers = "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers .= "Content-Transfer-Encoding: 7bit\r\n";
        $headers .= "From: " . $from . "\r\n";

//SEND THE EMAIL
        mail($to,$subject,$message,$headers);
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

remove the comma in $message and see what happens
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

It still doesn't send.

The weird thing is that it works when sent from a domain other than its own.

i.e.

all emails should be sent to me@mydomain.com

When sent from someotherdomain.com it works fine.

However, when sent from mydomain.com it doesn't work!

By the way, all emails are being sent via mail().
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

It seems to be a mail server configuration problem, not coding problem.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Do you have any more info on the server config problem?

I know its a weird request but I have been corresponding with the server guys and they keep saying "we're not programmers" and "we can't really do much else".

They frustrate me because i know it works!!!
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

1. I think that the mail server config is wrong because you are able to send e-mails from domain which is not served by the mail server itself.
2. Try to send e-mail from one mail account to another, both in your domain, by using a your favourite mail client...
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Sent myself an email and I receive it.

You see my script work when sending out emails but they just dont work when incoming from same domain.
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

Are you trying to send Spam?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Does it work when your script sends emails from your domain to other domain (e.g. your gmail account)?
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

No not trying to send spam.

Yes it does work when i send a message from my domain to an external account (gmail, hotmail etc...).
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Hm, strange ...
Try

Code: Select all

mail($to,$subject,$message,$headers, "-f $from");
and see if you receive any error-mail in your $from e-mail.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply