Page 1 of 1

Problem with mail()

Posted: Tue Jun 14, 2005 10:01 am
by FenixDarkclaw
I have the follow code, which is suppose to take data from a form and send it in an email. Everything seems to work, the form submits, the page runs with no errors and even my little bit of error checking says the mail was sent. But the mail is never received. I've used formmail.pl and other prewritten script for this as well and I have the exact same problem. Any ideas?

Code: Select all

<?php
$message = '';
echo "POST/GET Variables: <br>";
foreach ($_POST as $key => $val)
if ($key != "recipient" && $key != "redirect" && $key != "print_config" && $key != "required" && $key != "Submit")
$message .=  "$val<br>";
$header = "From: ";
$header .= $email;
$header2 = "-f";
$header2 .= $email;
echo "$message";
$ok = mail($recipient, $subject, $message, $header, $header2);
if ($ok) {
echo "Mail succesfully sent to: ".$recipient;
} else {
echo "Error: Unable to send mail to: ".$recipient;
}
?>

Posted: Tue Jun 14, 2005 8:11 pm
by harrison
Did you correctly configure you php.ini regarding SMTP server and port?
This section is located after a bunch of extensions config:

Code: Select all

&#1111;mail function]
; For Win32 only.
SMTP=localhost
smtp_port=25

Posted: Tue Jun 14, 2005 9:37 pm
by Ambush Commander
Where's your server? Is it a home server, a shared hosting server?

Posted: Wed Jun 15, 2005 7:07 am
by FenixDarkclaw
My php.ini looks like this:

Code: Select all

&#1111;mail function]
; For Win32 only.
SMTP=localhost
smtp_port=25
And my server is the server at my job (School server) which I have little knowledge of how it is set up unfortunatly.

This is quite the confusing development, and I apprieciate all the help.

Posted: Wed Jun 15, 2005 7:19 am
by Chris Corbyn
At least two possibilities

1. SMTP isn't installed or running on localhost (it could be provided by an ISP).
2. The mail is being filtered as junk by the recipient

Try searching by the way. This has been asked umpteen times here before ;)

Posted: Wed Jun 15, 2005 7:20 am
by shiznatix
one thing that catches my eye is

Code: Select all

foreach ($_POST as $key =&gt; $val)
if ($key != &quote;recipient&quote; &amp;&amp; $key != &quote;redirect&quote; &amp;&amp; $key != &quote;print_config&quote; &amp;&amp; $key != &quote;required&quote; &amp;&amp; $key != &quote;Submit&quote;)
$message .=  &quote;$val&lt;br&gt;&quote;;
the lack of brackets there but its still legal and all just wondering what exactly you want where cause they style gets confusing fast.

maybe just try doing somtin real simple like

Code: Select all

mail('myemail@server.com', 'did you get this email?', 'I HOPE YOU DID!');
and see if you end up getting it

Posted: Wed Jun 15, 2005 7:50 am
by Syranide
that last field will likely set you back as it isn't a valid SMTP-header.
EDIT: 'I HOPE YOU DID!'