Page 1 of 1

Can't figure out Mail()

Posted: Thu Mar 23, 2006 11:20 pm
by nic
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hey - a seemingly very simple issue is giving me more trouble than it should be. I'm trying to get php to send an email. Here's my code:

Code: Select all

$to = 'example@host.com';
$subject = 'the subject';
$message = 'hello';
$headers = "From: example@host.com\r\n
			Reply-To: example@host.com\r\n
			X-Mailer: PHP/" . phpversion() ;

if(@mail($to, $subject, $message, $headers))
	echo "mail was sent successfully" ;
else
	echo "&%*@!!" ;
I'm running an Apache web server on an OSX machine and I changed the following lines in my php.ini file:

Code: Select all

;sendmail_from = example@host.com
;sendmail_path = /usr/sbin/sendmail -t
The mail function seems to run without any problem, but the message never reaches the destination. Any thoughts?


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Mar 24, 2006 12:27 am
by s.dot
take the ; off the beginning of the lines and remove the @ infront of mail()

put this at the top of your script

Code: Select all

ini_set("display_errors","on");
error_reporting(E_ALL);

Posted: Fri Mar 24, 2006 1:40 am
by nic
well here's my code now:

Code: Select all

<?php

ini_set("sendmail_path", "/usr/sbin/sendmail -t") ;
ini_set("display_errors", "on") ;
error_reporting(E_ALL) ;

$to = "example@host.com" ;
$subject = "the subject" ;
$message = "testing testing" ;
$headers = "From: example@host.com\r\nReply-To:example@host.com\r\n" ;

if(mail($to,$subject,$message,$headers))
	echo "sent" ;
else 
	echo "not sent" ;

?>
and I can't get it to generate an error, nor can I get mail() to return false with any parameters. What, besides php.ini, needs to be configured in order for the mail() function to work? Why is php seemingly not communicating at all with sendmail?

thanks