Forum Moderators: coopster

Message Too Old, No Replies

What is wrong with my mail() function

         

anand84

9:21 am on Apr 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have the following code in my code


<?php
$mail_to="abc@example.com";
$mail_from=$_POST['from'];
$mail_sub="WebmasterWorld Example";
$mail_mesg=$_POST['content'];

if(mail($mail_to,$mail_sub,$mail_mesg,$mail_from))
{
echo("<span class='textred'><b>Thanks for your contribution<b> </span>");
}
else
{
echo("<span class='textred'>Submission Failed.Please retry. </span>");
}

?>

Here 'from' and 'content' are a text box and text area respectively. I cannot find my mistake here..On clicking, I do get my thank you message..But the mail never gets delivered to my e-mail. Can somebody point out the problem?

Birdman

10:47 am on Apr 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The fourth argument in the mail function is for headers. "From" is one of the possible headers but you must format it correctly.

$mail_from = 'From: ' . $_POST['from'];

So it would look like "from: me@blah.com"

anand84

1:21 pm on Apr 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you Birdman. But still have some problem. The suggestion you made also did not get me the email. And then I tried this


$mail_from =$_POST['from'];
$mail_mesg=$_POST['content'];

if(mail($mail_to,$mail_sub,$mail_mesg,"From: $mail_from\n"))
...

Still this doesnt work. I just got to know that the "\n" should be necessarily be there at the end of the header. Is this some problem with my mailbox. But I tried more than one email websites..I dont seem to be getting the email at all.

Birdman

2:36 pm on Apr 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



At this point, I would run a simple test to see if it's a server problem:

mail('you@youremail.com', 'test', 'test');

If you recieve the test email, then we can look harder at the script to find the problem.

anand84

4:08 pm on Apr 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Guess it is indeed a server problem. I am not receiving it. I have wasted one full day trying one single line of code. I just feel too stupid.

Birdman

4:10 pm on Apr 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, that happens to everyone at some point. Just get in touch with your host and I'm sure they'll fix it.