Click to See Complete Forum and Search --> : Why won't mail() send?


Patty5
10-14-2008, 07:04 PM
I am running this on windows, with php5 and I can't figure out why this script will not send the mail. It echos the msg which reads "Sorry,your comments have not been sent".

I'm sure this is something simple as it works perfectly any other time.

Can someone please help me out?


<?php

if (isset($_POST['submit2']))

{

$message .= "<br><b>Name:</b> " . strip_tags($_POST['name']). "\n";
$message .= "<br><b>Email:</b> " . $_POST['email2'] . "\n";

$message .= "<br><br><b>Comments:</b><br>" . strip_tags($_POST['comments']) . "\n";

$headers = "Content-type: text/html\r\n";

$messages = "<html><head></head><body><br><br><b>Feedback From Website</b><br>" . $message;

$messages .= "</body></html>";

if(mail('name@mydomain, 'Website Feedback', $messages, $headers))

{
$msg = "Your comments and concerns have been sent. A representative will be in contact with you shortly.<br><br> Thank you!";

}
else
{
$msg = "Sorry, your comments have not been sent.";
}

}//end if

?>

scragar
10-14-2008, 07:45 PM
How have you configured it(atleast check the config anyway)?

http://uk2.php.net/manual/en/mail.configuration.php -- check your php.ini file.

or just run this code, your choide:

<?php

$inis = Array('SMTP', 'smtp_port', 'sendmail_path');// from not important
foreach($inis as $key=>$val)
echo "\t{$val}\n<code>\n";
var_dump(ini_get($val));
echo "</code>\n";
};

Patty5
10-14-2008, 07:50 PM
I ran this code and nothing displays. Is there a certain place I am suppose to upload the script to?

Thank you for the quick reply!

scragar
10-14-2008, 07:54 PM
my mistake, missing the opening brace:
<?php

$inis = Array('SMTP', 'smtp_port', 'sendmail_path');// from not important
foreach($inis as $key=>$val){
echo "\t<p>{$val}</p>\n<code>\n";
var_dump(ini_get($val));
echo "</code>\n";
};

Patty5
10-14-2008, 07:58 PM
This is what it returns:

SMTP

string(9) "localhost"
smtp_port

string(2) "25"
sendmail_path

bool(false)


I'm not sure what this means!!!! How can I make the mail() script work with this information?

scragar
10-14-2008, 08:16 PM
I'm going to assume that your running this on a local host without a mail server running, right?

You have 2 choices if I'm right, no 1 is to install and run a mail server as well, but this would be extra resources etc, the better solution is 2, either edit your php.ini config file to set the STMP server(normaly something like stmp.SITE.com and the port(25 is most common, but not always right)) or use the ini_set() (http://php.net/ini_set) function to set it on the page if you can't edit the config.

Patty5
10-14-2008, 08:25 PM
No, I'm actually running on a web server!

So would this be correct:


ini_set($smtp_port, "25");
ini_set($SMTP, "smtp.mydomain.com");


Then put this code before the mail() runs???

scragar
10-14-2008, 08:30 PM
close:
ini_set('smtp_port', "25");
ini_set('SMTP', "smtp.mydomain.com");
You shouldn't have any problems with this if it's on a server, your mail config should be fine with using localhost on port 25, unless your port is different.

since you are running it on a server are you use it's running a mail server(with STMP, some servers are pop only, check that)? And if so, check the port it's listening to.

Patty5
10-14-2008, 08:37 PM
Well this makes me think there is something wrong with my code then. I have ran other mail scripts from other domains hosted on the same server. For example, the following runs. It is run in fckeditor directory in the same domain.


if (isset($_POST['sendSubscribers'])) { //send to ALL subscribers

$fromEmail = stripslashes($_POST['newsFrom']);
$subjectLine = stripslashes($_POST['newsSubject']);


$sValue = stripslashes($_POST['FCKeditor1']);
$expression = 'src="';
$insertvalue = 'http://www.domain.com';

$sValue = str_replace($expression, $expression.$insertvalue, $sValue);

$message = $sValue;

$headers = "Content-type: text/html\r\n";
$headers .= "From: ".$fromEmail."\r\n";

$messages = "<html><head></head><body><br>" . $message;

$messages .= "</body></html>";

$count=0;
$emailsNotSent = array();

include("../../inc/conn.php");

$result = mysql_query("SELECT * FROM newsletter");
$num_rows = mysql_num_rows($result);



while ($getAddress = mysql_fetch_array($result))
{

$sendMailTo = $getAddress['email'];

if(mail($sendMailTo, $subjectLine, $messages, $headers))

{

$count++; //email count of success messages sent

}

else
{
array_push ($emailsNotSent,$sendMailTo);
}//end if

}//end while

$msg = $count . " newsletters are being sent to members of your subscriber list. You will be sent and email when sending has completed.";

}//end main IF

scragar
10-14-2008, 08:57 PM
your missing a single quote after the email, but I doubt that's your problem, since it would have thrown an error then..

Patty5
10-14-2008, 09:19 PM
Well, I've tried setting ini_set() for both the port and smtp and it still doesn't work. I added single quotes and double quotes around the strings and it just doesn't send!

I don't understand.... how can it work in one directory and not in another?

HAS Studios
10-14-2008, 09:35 PM
If all else fails I suggest using phpmailer - an app I have come to rely on for getting round this rather tricky and tiresome sort of problem.

Patty5
10-14-2008, 09:40 PM
Thanks so much for your help and for the suggestion.

I'll get it figured out one of these days! I'll look at phpMailer and see what that is all about! Perhaps that may be a simple fix I'll grow to love!

Thanks again!

HAS Studios
10-14-2008, 09:43 PM
Its certainly one I've grown to love! :)