mail() question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

mail() question

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

What operating system? And what does your sendmail_path look like in php.ini ?
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post 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
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post 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...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

yes whether he has to give path of sendmail..?
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

run this script
<?
phpinfo();
?>
from their you can find the php.ini path that php is using...
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post 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
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

the code seems to be correct
but mail server should only send the mail when mail function is called by php ... :roll:
Post Reply