Page 1 of 1

mail() question

Posted: Tue Oct 21, 2003 8:42 pm
by SBro
Hi all, I have the following code

...
$success = mail($emailaddy, $subject, $message, $headers);
if ($success)
echo "The email to $emailaddy from $from was successfully sent<p>";
else
echo "An error occurred when sending the email to $emailaddy from $from <p>";

I assume that is all correct, but when it is executed I get the error:

Warning: Failed to Connect in C:\blahblah\insertcal.php on line 36
An error occurred when sending the email to (sent email) from (from email)

I'm guessing the error is in that I don't have SMTP server set up correctly (i'm testing on my local machine atm). I have looked on the net for suggestions etc and haven't found much. I have to set up my php.ini file? Any suggestios on what I need to do to setup the SMTP properly (if that is indeed the problem) would be appreciated, thanks in advance.

Posted: Tue Oct 21, 2003 8:43 pm
by markl999
What operating system? And what does your sendmail_path look like in php.ini ?

Posted: Tue Oct 21, 2003 10:01 pm
by SBro
server running on XP

php.ini (located in server/php)

[mail function]
; For Win32 only.
SMTP = localhost

; For Win32 only.
sendmail_from = me@localhost.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =


Thanks

Posted: Wed Oct 22, 2003 2:11 am
by devork
in unix sendmail is used to send the mails
is in windows your sendmail or other is running to send mail
and check the path php.ini of that pogramme that will handl your mail operations...

Posted: Wed Oct 22, 2003 3:24 am
by twigletmac
When testing at home I tend to use my ISP's SMTP server as I don't have my own. This may work for you too.

Mac

Posted: Wed Oct 22, 2003 4:57 am
by devork
yes whether he has to give path of sendmail..?

Posted: Wed Oct 22, 2003 5:14 am
by SBro
Yes I've tried putting my isp's mail server aka

[mail function]
; For Win32 only.
SMTP = isp smtp server

but still received the same error, I feel it maybe something to do with where php.ini is located?

Posted: Wed Oct 22, 2003 5:43 am
by twigletmac
Check the output of

Code: Select all

<?php phpinfo(); ?>
if you're worried that you're editing the wrong php.ini, it'll tell you which one it is getting its values from.

Mac

Posted: Wed Oct 22, 2003 5:48 am
by devork
run this script
<?
phpinfo();
?>
from their you can find the php.ini path that php is using...

Posted: Wed Oct 22, 2003 7:34 am
by SBro
Ok I now have it sending mail...but (lol) it seems to be sending the same message over and over again? any ideas on why and how to stop it? (stopping the server will stop it ?) here is my code

$equery = "SELECT email_address, first_name FROM users WHERE first_name = '$applies_to'";
$result = mysql_query($equery);
$enum=mysql_num_rows($result);


$emailaddy = "email@emailaddress";
$first_name=mysql_result($result,"first_name");

$from = "another@email.com";
$subject = "New event added $title";
$message = "blahblah blah message here";
$headers = "From: $from\r\n";

$success = mail($emailaddy, $subject, $message, $headers);
if ($success)
echo "The email to $emailaddy from $from was successfully sent<p>";
else
echo "An error occurred when sending the email to $emailaddy from $from <p>";


Thanks for your ongoing help

Posted: Wed Oct 22, 2003 9:25 am
by devork
the code seems to be correct
but mail server should only send the mail when mail function is called by php ... :roll: