Page 1 of 2

Using mail()

Posted: Mon Aug 20, 2007 10:16 am
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]

Re: Using mail()

Posted: Mon Aug 20, 2007 3:02 pm
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

Posted: Tue Aug 21, 2007 4:15 am
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?

Posted: Tue Aug 21, 2007 4:53 am
by iknownothing
no subject?

Posted: Tue Aug 21, 2007 5:32 am
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);

Posted: Tue Aug 21, 2007 5:56 am
by iknownothing
remove the comma in $message and see what happens

Posted: Tue Aug 21, 2007 6:09 am
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().

Posted: Tue Aug 21, 2007 7:13 am
by VladSun
It seems to be a mail server configuration problem, not coding problem.

Posted: Tue Aug 21, 2007 7:36 am
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!!!

Posted: Tue Aug 21, 2007 7:52 am
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...

Posted: Tue Aug 21, 2007 8:21 am
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.

Posted: Tue Aug 21, 2007 8:24 am
by iknownothing
Are you trying to send Spam?

Posted: Tue Aug 21, 2007 8:24 am
by VladSun
Does it work when your script sends emails from your domain to other domain (e.g. your gmail account)?

Posted: Tue Aug 21, 2007 9:37 am
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...).

Posted: Tue Aug 21, 2007 9:44 am
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.